[SOLVED] How to tweak shader_param with code ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ash_Grey


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():

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 set_shader_param 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


:bust_in_silhouette: Reply From: lewis glasgow

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

func _ready():

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 ?

Ash_Grey | 2021-08-05 09:56