In BP, how to restore the materials that were set in editor, as opposed to materials set in mesh?

Say I import a mesh, and in the mesh editor it uses “Black” material. Then I put this mesh into the model, and set the material on the actor to “White”. Then I make this mesh into a blueprint, and make a boolean to switch the material to a third material, “Green”.

I’ve tried a few methods, but cannot get the material to revert to “White” when required. Instead, it reverts to “Black”.

When the switch is active, I have attempted to directly set the “Green” material. I have also attempted to create and set a Dynamic Material Instance using the “Green” material as the parent. Either method changes the material as required.

When the switch is turned off, I cannot get the “White” material restored. If I use Set Material and leave the material pin empty (ie None), it reverts to the meshes default material, ie “Black”. I want it to revert to “White”, the material set in the editor. I have attempted to save the original materials to a variable using the construction script, but it saves the “Green” material if the dynamic material instance is the active material when the construction script runs.

In this use-case, changing the material of the static mesh asset is not practical, as there are hundreds that import with a default material. Also, I may not want each actor using the asset to have the same material. Lastly, I want the materials to be completely independent, not already being material instances themselves.

How can I fix this?

You can set the white material in the mesh itself unstead of black: not in the model or a blueprint, but in the mesh editor. Or, if you need the black one to pertain, just set the white material instead of reverting it to default.

I mentioned in the last paragraph that changing the material in the mesh editor is not practical for 2 reasons (the amount of meshes, and the fact that 2 actors using the same mesh may have different materials). Regarding your second suggestion (manually setting the material in the blueprint to my “default”), I was hoping to have a common blueprint that could be used for many meshes and actors, each possibly having different materials, and thus there is no “default” that can be set in the blueprint. I would like it to be automatic and dynamic, based upon what was configured in the editor.

In this case you can save the default material to a variable on Begin Play or in the Construction Script and create a function that will run for different blueprints with a material stored in the bp variable.

The default material is saved in the mesh asset, and if you change it in the bp and don’t save it somehow, it will always go back to the mesh material.

Here’s what I came up with to cache the materials. This allows the material to be set to a different material from within the editor, even if the temporary material is the active material.

1 Like

Try to run this screenshot, it should reset the material to the original of the mesh.