I’m making skybox generator that spawns skybox, clouds, sun, fog volume etc. right in the editor. It’s based on BrushBuilder class, but instead of changing shape of the builder brush, it spawns all this stuff. So, I was going to add a previewer, that changes skybox to the needed time of day, allowing designers to see results of their work in the editor without having to run the game after every change. The thing is that I need to create material instances and assign them to skybox mesh.
MeshMaterial = StaticMeshActors*.StaticMesh.StaticMeshComponent.GetMaterial(StaticMeshActors*.Materials[j].MatID);
StaticMeshActors*.Materials[j].MatInst = new(None) Class'MaterialInstanceConstant';
StaticMeshActors*.Materials[j].MatInst.SetParent(MeshMaterial);
StaticMeshActors*.StaticMesh.StaticMeshComponent.SetMaterial(StaticMeshActors*.Materials[j].MatID, StaticMeshActors*.Materials[j].MatInst);
That works both in the editor and when the game is running, but calling this code in the editor, leads to a problem. With material instances created in the editor, I cannot save the map or play it because of this error:
The reason is clear - meshes have this thing assigned to Materials array:
MaterialInstanceConstant'Transient.MaterialInstanceConstant_101'
Is there anything I can do to fix that problem? Maybe I’m just creating material instances in a wrong way? I could try to make another script that clears transient instances, but having to use it every time one needs to save or run the level would be really annoying.