Download

UPROPERTY() UMaterialInstanceDynamic* Prevents maps and blueprints from saving

I posted a thread about this before, but maintenance happened and then it was gone.

UPROPERTY()
UMaterialInstanceDynamic* DMat;

Having this in any class used in a blueprint or added to a level will prevent that blueprint or level from being able to be saved. So far, the only work around I know is to remove the property in code, make the changes in editor and save, then re-add the code. This is a very painful work around, especially since I continue to use more and more material instances, and I am wondering if anyone has found another solution to this. Any help is greatly appreciated.

I think I probably should show this message to clarify what I mean.

What is creating/assigning the MID? The error message indicates that it is referencing an object that is created in the transient package, in other words an object that will not get saved out with the blueprint. Either the MID needs to be created in such a way that it is part of the hierarchy of objects that will get saved out by specifying its Outer correctly when creating it or your property needs to be marked transient so that the reference to the MID is not saved and you are not left with a reference to an external object.

I tried doing it in the constructor, and doing in an initialization function. I also tried UPROPERTY(Transient). None of these solved it for me. Currently, I removed the property entirely. I create and assign the MID as a local variable in a setup function, then when I need to alter the parameters, I use a combination of GetMaterial and Cast to get a local pointer. This seems to work fairly well for me, but I can’t help but feel like I am doing this “wrong” or at least not the way that was intended. Would it be possible for you to post an example snippet?