Performance cost of Dynamic Material Instance?

Hi!

I figured whenever I created a Dynamic Material Instance, a new material was made with a number at the end,
eg : MaterialInstanceDynamic_345 , and it keeps increasing as I called it from my blueprint.

Let’s say I create a dynamic material instance each time I clicked a mouse button, does it overwrite the old one? or is it still stored somewhere? Is there something I should be aware when creating a dynamic material instance?
That number makes me feel uneasy :expressionless:

cheers!

1 Like

I’m also curious about this. I’m currently assuming it’s just a memory cost.

Hey Vanadot & ,

A Dynamic Material Instance (DMI) should be created in the Construction Script of the object it will be applied to, and then have the result of the “Create Dynamic Material Instance” node saved to a variable immediately after creation.

Once that occurs you can use the DMI variable to call any of the “Set Scalar/Vector Parameter” functions to update the material instance in the event graph on tick, or begin play etc. Because you created and use the DMI variable, you are not creating a new instance each time you make a change.

I have seen a few examples where people forget to save the DMI variable, or create the dynamic instance somewhere other than the construction script, both of which will either cause an error or will create a new instance on each change. So long as you do what I mentioned in the first paragraph above, the performance is not an issue, it will be nearly as fast as using a normal material instance, and will not increase the “number” you mentioned in the original post.

Cheers,

1 Like

I’m noticing that the number of DMI is still increasing as soon as you move the BP that is instanced in the level, as the construction script, which creates DMI, is re-run each time then. Is that normal, and no way to avoid it?

As long as you do as says and assign the DMI to a variable once it’s created, and check that variable before creating one, then it should be fine. Note that the DMI variable must be exposed (Instance Editable), else the Construction Script can’t set it and will keep thinking it’s empty.

Other option, if you don’t need to see it in the editor, is to do it in BeginPlay instead of Construction Script, then the variable doesn’t have to be Instance Editable and you know it’s only going to happen once.