0 votes

EDIT: PROBLEM SOLVED

I just needed to reference the shader in the code beforehand.
Here's what my code looks like in case anyone stumbles here.

func _ready():
    pulse_outline()

func pulse_outline():
    var material = load("res://Shaders/outline.material")
    material.shader = load("res://Shaders/outline.shader")
    material.set_shader_param("outline_thickness", 1)

Hello everyone.

I'm trying to animate the outline thickness of my object's shader in an out, kind of like a "breathing" animation, to indicate that it has to be clicked.
For now, I'm only trying to make my code act on the outline shader by telling it to set the outline thickness to zero.

I've went through a lot of videos and tutorials, even the Godot discord, and I couldn't narrow down the problem. It seems like there is an issue with using the "SpatialMaterial" that doesn't allow me to call on the setshaderparam function. However the shader I'm trying to act on (next pass) is not a SpatialMaterial, it's a ShaderMaterial.

Could you please tell me what is wrong with my code ? How can I get it to work ?

Here are some screenshots, thank you all for your help.

Node Setup and different Materials

Object

Godot version v3.3.2
in Engine by (56 points)
edited by

1 Answer

+1 vote
get_surface_material(0).set_shader_param("param",value)
by (458 points)

Thank you for answering, but I still get some errors, maybe it can help narrow down the problem.

func _ready():
    print(pulse_outline())

func pulse_outline():
    $MeshInstance.get_surface_material(0).set_shader_param("param", value)

This returns as a "Null Instance". This is confirmed by using get_surface_material_count, which when printed only says Null. This is also null when I use get_active_material(0).

Any ideas ?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.