In my game, I have an object hierarchy whose root object calls the DontDestroyOnLoad function in its awake function. As a result, all the objects in this hierarchy are not destroyed when I load a new scene.
However, I have a mesh render object in this hierarchy which will lose all its materials when loading a new scene. The object is a sphere mesh with 5 materials and the object itself is not destroyed. The weird thing is that it has a child object which does not lose its material in the process.
I have solved the problem by adding the following code in its awake function :
function Awake() {
for(m in renderer.materials)
DontDestroyOnLoad(m);
}
However, I do not understand why my materials are not automatically preserved from destruction. I have many other objects which do not lose their materials at loading, without having to save them explicitly.
Can someone shed some light on this ?