Performance cost of Dynamic Material Instance?
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 :|
asked Feb 17 '16 at 07:33 PM in Using UE4
Hey Vanadot & lukefwilson,
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.
Follow this question
Once you sign in you will be able to subscribe for any updates here