Change the texture of a duplicated prefab in unity (How to) #unity

Published in IT Solutions

Fix the problem that changing a duplicate prefab material changes the material on the original

Help! I can't change the texture/map of a prefab I duplicated without also changing the original Prefab in unity game engine!

Does this sound like the problem? You duplicated a prefab in Unity and when you go to change it's texture, map or colour you find the original prefab changes too? You ask yourself; Is this an instance? Are the prefabs connected? Do I have to somehow ungroup them, disconnect them or break them?

 

The good new is now there is no connection you need to break apart even if changing the texture/map on the new one, changes the original. The problem is simply your understanding of textures in unity and it means the fix is easy.

Material vs Texture in unity:

In unity a material is made up of textures and it that can be applied to a large number of different kinds of objects. A material is referenced by the prefab which means it is exteeranl and not stored in the prefab.

Material view inspector unity game engineIn the Unity inspector view you can see how a material is made up of various textures (maps)

If you expand the triangle in the inspector panel on the material of a duplicated prefab and change any of the textures, you are changing the Material. That same material is still used by the original prefab.

How to fix the problem:

Here is the easiest method I have found to fix this.

  1. Find and duplicate the material which is used by both prefabs.
  2. Rename the new material
  3. Change the textures in the new material to be the way you want.
  4. Change the material of the duplicated prefab: The easies way I have found is to simply drag the prefab into the hierarchy pane of the scene and then with the object in view you can drag and drop the new material onto the object (or parts of the object) when the object has the new material correctly in place, drag and drop it from the hierarchy pane back directly on top of the new duplicate prefab. The duplicate prefab with be updated and now you will have the new material on the new prefab.

The duplicate prefab changes the material of the original prefab because the were using (referencing) the same one and the material. There is no need to ungroup the new prefab or break an instance, you just need to make a new material and apply it (as decrivbed above). Job done!