0
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?

2
  • It seems you are using a plugin to perform some actions, it could be overriding your script. 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. Commented Mar 13 at 16:04

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.