create dynamic material instance not working?


I seem to have a problem with the create dynamic material instance. I have the following scenario: I have set up an instance material to multiple objects, and I’d like to change a parameter of that instanced material, so that all the objects that have that material will be affected. But this is not happening.

Here are some screenshots of how I have it setup:


Thank you,

Can anyone help me, I am really stuck…

Umm, without double checking the docs…

You need to iterate though all the objects that have he material and assign this MDI to them or iterate through them and create MDI’s from their materials. Right now you seem be creating an orphaned MDI, so any changes to it have no relationship to the objects in the scene which have instances of their own materials.

Thank you for the response Anadin.
Is there any other way that I can change a parameter of a material instance and have all the objects that already have the same material applied, be changed. Just like when working in the editor.
I have a lot of static meshes in the scene, and each static mesh has 3-4 material slots, and the instanced material is not always in the same slot. So this will be a nightmare to set up for each static mesh, if I have to iterate through them all.

I think the problem is that you have no reference of the Material in the world and trying to change it, this way you are changing a plain material instance… As Anadin said, you must get all these references from all the actors/objects that shares this material to change them, one by one.

Yup, the thing is when the game starts effective new instances of the meshes/actors etc. are created, they in turn have instances of the original material instances. You need references to these so that you can convert them to MDI’s and then swap modify them. It is all done by name so the multiple slots thing may not be too painful. This is done for a button but you can get the concept…

Could you tell me how can I get all the references of the material from all the actors?

I would do something like this:

  • Create a BP Actor Class MaterialActor
    • Add a MeshComponent and inside the construction script, create a dynamic material instance from the MeshComponent reference, store the resultant value in a Material Instance Dynamic reference;
    • Create an integer called MaterialIndex and node it on Element Index;
    • Inside the MaterialActor class, create a function SetMaterialColor with a Color Input;
    • Inside the SetMaterialColor function, use the SetVectorParameterValue node from the MID reference and node it with the input color.

After this, create a child from this MaterialActor class and set its static mesh. Change the MaterialIndex default value to the actual index your Material is set.

Create an event that GetAllActorsFromClass (MaterialActor), use a for each loop and, from the resultant reference, call SetMaterial function.

Try it, I think it might work.