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?
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?
Share Improve this question asked Mar 13 at 3:49 gcs_devgcs_dev 1012 bronze badges 2- It seems you are using a plugin to perform some actions, it could be overriding your script. – liggiio Commented Mar 13 at 12:24
- This code is part of a panel script which gets called by the plugin itself. The plugin script doesn't do any setting or getting of material parameters. – gcs_dev Commented Mar 13 at 16:04
1 Answer
Reset to default 0In 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.