How to Destory the Dynamic Material Instance in memory?

I make a Dissolve Effect BP in my weapon when I destroy object it will have a dissolve effect, so…
The dynamic material instance will not destroy together with the object and be there forever.
How can I destroy the Dynamic Material Instance when it can not disappear?

Blueprints have a Garbage Collector. Any object that is no longer referenced in the world will be automatically destroyed (edit: I meant deleted). If you set the MaterialInstanceDynamic variable to null, the GC should kick in and remove it from memory.

I believe the system received a performance boost in 4.16 or 4.17, so this happens pretty quickly.

In your case, I’d set the parameter controlling the opacity of the effect to 0 and clear the referencing variable or destroy the actor that stores it.

1 Like

Thank you, let me test first.

I add a Set Texture Parameter Value note to make the texture null, it works…but before the DynamicMaterialInstance disappear the texture will go back to the gray grid Texture. I don’t want this shows up. So I add an Opacity note and then set null, but the result goes back to the beginning…

So, hold on. You create a MID in the weapon blueprint and apply it to the target of the weapon. The target gets destroyed. So far so good.

I’d simply set the MID reference to null and forget about it:

Thank you first. I try you note, it will become this all gray, sometimes it will disappear, sometimes don’t (゚Д゚≡゚д゚)!?
Perhaps no way to solve the problem with Blueprint …

I know where the problem is, probably because of my DestroyActor read and isValid? Node problems, i will solve it but not soon, thank you very much!

214887-dynamicmaterial3.png