Can't change arrays in a shader when referencing them through code

Godot Version

4.4.1.stable

Question

I’m trying to change the values of an array in my shader to change the shader’s behavior when the player dies. What ends up happening is that the shader itself doesn’t react to it’s arrays being changed. Also, when I print the array in the same script that I modify it in, the values of it have changed, so it’s not that the values are overridden or something else like that.

On top of this, the shader does react to other modified non-array variables.

Is this just a bug or is there something I can do to fix it?

Code that modifies array:

var output_array = %ColorRect.get_material().get_shader_parameter("output_array")
		
output_array.set(0, Vector4(0.0,0.0,0.0,1.0))

Shader code defining variable.

uniform vec4 output_array[4];

this retrieves the current shader value as a copy, any edits to the variable are not propagated back to the shader. You must use set_shader_parameter to assign a value.

Thanks for the reply! Setting specific properties of an array doesn’t work through set_shader_parameter. I was however able to figure out this workaround.

var modified_output_array = %ColorRect.get_material().get_shader_parameter("output_array")

modified_output_array[0] = Vector4(0,0,0,100)
%ColorRect.get_material().set_shader_parameter("output_array", modified_output_array)