Hello everyone!
I have been playing with the material instancing lately, and I found something very weird happening. If I didn’t asign a unique name to the instantiated materials the whole project crashed. It took me a while to understand where the problem was, and I was really surprised about it. Just to give you a little bit of context, this is what happened:
I have an abstract blueprint class called InteractableActor that extends Actor. This class has a mesh called “Button” that is used to indicate to the player what button to use during the game. Every actor I have in my scene extends this class, and has an exposed variable that indicates the button to press. Every time the child class updates the button (this can be done both on BeginPlay and at runtime) the blueprint instantiates a new material, assigns the right texture for the button, and assigns it back tothe mesh.
For some reason, the button was correctly assigned to the object, but the texture wasn’t. Most of the objects had the same texture throughout the game, even though the assigned button was correct. While updating some of these textures at runtime the whole thing crashed. I tried everything I could, but with no luck. It seemed that despite the dynamic material instancing of each object, the materials were in fact linked. To debug I tried to give each single material the object’s name, and it suddenly started working.
This behaviour is consistant with what I saw in my testing level, each object was working in a standalone environemnt, but when in a larger environment, it caused conflict and crashed. So my question is: do I need to dig it deeper, or the name is actually important? Can this be a bug or it’s something expected?
Engine version is 4.21