Search Unity

Prefab material and instanciated object materials

Discussion in 'Editor & General Support' started by Maker16, Aug 24, 2011.

  1. Maker16

    Maker16

    Joined:
    Mar 4, 2009
    Posts:
    779
    I have a prefab object with multiple materials. Every clone of this objects needs these materials. However, each clone will need to be able to set their materials differently given whatever state they me be in, independent of the others.

    Currently, if I instantiate multiple clones of the same prefab, they share linked materials. If I change the material on one clone, all of the others also change their matierial. How do I set it up where, when one clone changes it's material, the other clones do not?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Change renderer.material instead of .sharedMaterial. When you do that, it makes a new instance of the material for the object. Or you can create the material instances yourself, which is sometimes necessary, such as if you want to clean them up. (Because if you let Unity make the instances, there's no easy way to refer to them.)

    --Eric