var node = currently_selected_MeshInstance3D
var materials = []
for i in range(node.get_surface_override_material_count()):
var mat_or = node.get_surface_override_material(i)
if mat_or and mat_or is ShaderMaterial and mat_or not in materials:
materials.append(mat_or)
for material in materials:
material.set_shader_parameter(param_name, param_value)
I use the above code to set parameters found on all ShaderMaterials attached to the currently selected MeshInstance3D.
When executed, the code works, the parameters are correctly updated and the object in the 3D view reflects this, however, when I then deselect that object and then select it again, the ShaderMaterial's parameters, as reported in the editor, have reverted to how they were before execution of the code even though the object in the viewport still appears to be using the updated parameters.
For visual reference, please see this video.
How do I correctly set ShaderMaterial parameters with gdscript in such a way as to make them stay set?
In the end it turned out the problem was that I was setting IntParameters with float values.
I changed all the shader parameters to float types and now the values altered by the script stay altered.