MaterialInstance SetParameterValue Performance Impact

I have several instances of a material. The editor user can change the parameters of these instances via variables in actors. I make the change with something like: materialInstance.SetParameterValue(“rgba”, Prgba); setting a material parameter value (in this example the base color). Is there any appreciable overhead to changing these parameter, e.g. if I have a task ticking at 1 second intervals setting 8 parameters on 20 different instances do I need to put in some checks so I only actually SetParameterValue if a value has changed or am I OK to just blindly reset them all every second?

Edit:
I figured a more elegant way to check if they need setting, but still interested if anyone has any performance insights into changing the material instances while they are in use.

This depends if you’re using C# or C++, because C# uses an additional bindings layer that converts values (esp. that material parameter value can be any object - scala, vector, texture, etc.).

If you’re looking for more optimal way you can also cache material parameters and set their values directly:

MaterialParameter param = Material->GetParameter(name); // cache parameter pointer
param.IsOverride = true; // call only once
param.Value = value;
1 Like

Perfect, thanks!