Some clarification about prefabs

Hi,

I think I’m starting to get the hang of the basic concepts and how Unity does things, but I am still a little confused about he relationship between a prefab gameobject in the Project window and instances of that gameobject in the hierarchy/scene. I’ll give a specific example which is confusing me. I have a prefab which consists of a transparent sphere which is used to trigger a sound via a script it contains. Inside this sphere is a plane on which there is a texture. Now, if I drag two instances of this prefab into the scene I can get them each to play a different sound if I change which sound the script is calling (via the inspector), but if I try to change the texture on the plane it changes on all instances in the scene. It does this even if I break the link of a given instance to the prefab (by, say, adding a light source to one of them).

Can someone please explain why this happens and also how I can have different objects have different textures without setting up a separate prefab for each one.

Thanks in advance.

Your confusion is understandable. Prefabs handle most things quite consistently, but there are a few exceptions. Most importantly: materials work differently. Materials are much like prefabs themselves: whenever you change a value, the change will apply to all objects using that material. Your prefab only stores a link to the material and not the values of it, so if you change something in the material, it will immediately apply to all the other objects using it.

If you want different textures on your prefab instances, duplicate your material and replace the texture in the new onw. Then drag the new material into your prefab’s renderer and it should work as expected.

That’s great Tomvds, many thanks. I have now managed to make my prefab instances display different textures and, more importantly, I think I understand why :slight_smile: