- Home /
Material Not Reverting Back
When i set the texture of a material i pass in, or the gameObjects material they dont revert back to how they where when i clicked play.
Is this intentional? If so is there anything i could do to counter this problem?
Answer by Tseng · Oct 09, 2011 at 03:16 AM
This happens, if you edit the sharedMaterial only and as far as I see it, it's intended as it's been that since I'm using Unity which is since 3.1.
This code will keep the new assigned texture even when you stop the player.
renderer.sharedMaterial.mainTexture = newTexture;
So you can either only use renderer.material.mainTexture = newTexture
which won't cause this, but it will prevent dynamic batching. On Mobile devices this may cause major slow down (low fps). On PC it's not that bad, but still if you're going for performance you may want to batch it. Of course, if your object is to big to be batched, it has no effect anyways.
Since there is no way I'm aware of where you can intercept "stopping" in the unity editor, you can't put it back in code neither
Well, you can use OnApplicationQuit() - that triggers in the editor, as well as the standalone. You can use that to do whatever resetting you have to do.
Answer by Eric5h5 · Oct 09, 2011 at 03:33 AM
Yes, editing project assets is always permanent regardless of being in play mode. You can instantiate the materials and edit the instances during play mode if you don't want changes kept.