Search Unity

Many objects with same material how to update only one object?

Discussion in 'General Graphics' started by TheCelt, Jan 4, 2020.

  1. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    742
    I have multiple objects with the same material applied, but i want to change the colour of just one object and not all of them by changing the material colour, how can i do this without having to make a new material for every single object to individualise them ?
     
  2. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,054
    If you have a reference to the Renderer ( meshRenderer ) for the object then you can simply use renderer.material.color as behind the scenes Unity will create a clone of the material prior to changing the property.

    Normally this catches developers out as they actually don't want a clone to be created in which case you should use renderer.sharedMaterial.color.

    Alternatively you can make use of MaterialPropertyBlock.