What is the difference?
You get the difference between a class and an object, yeah?
The difference between a material asset and a material instance is very similar.
If your scene has 200 renderers all referencing the same material asset, you can get away with using just one material instance to draw all of them. This is what
sharedMaterial gives you.
Now, let’s suppose you want to change the color of one of those objects. You can change the shared instance without changing every object. Solution? Create a second instance and tweak just that one. This is what
material gives you.
Unity handles this somewhat automatically:
- In general,
sharedMaterialalways gives you the “base” instance that’s shared between multiple renderers.
- The first time you access
material, Unity clones the
sharedMaterial, associates your renderer with the clone, and gives you the clone.
The difference is mainly important in editor scripting. Once the game is running, you usually want the implicit behavior of
material. If you’re just in the editor, though, you can avoid creating extra materials willy nilly by using
The difference between
sharedMesh is the same.
is it normal that once you get access to material, shared material is no longer available?