Search Unity

Best way to change colors of a lot of objects? (like the hierarchy search - scene view resource)

Discussion in 'General Graphics' started by Zimbres, Dec 23, 2017.

  1. Zimbres

    Zimbres

    Joined:
    Nov 17, 2014
    Posts:
    180
    Hi there,

    I would like to show some gameobjects with color, and others on black-and-white (like the scene view, when we use search on the hierarchy tab).

    Some friends says that the ideal path is to change the color of each gameobject, but... there's another way around? Something more cleaner, less specific?
     
  2. ifurkend

    ifurkend

    Joined:
    Sep 4, 2012
    Posts:
    350
    This can be done via shader. For simple color multiplication, check if the shader used by your mesh material provides either _Color or _TintColor, and apply Material.SetColor(). Changing to grey scale requires shader customization with simple maths. Either way, if you change the material from the project folder, the change will be applied to all meshes using the same material. Otherwise changing the material in a specific Renderer will create a new material instance, IOW a new drawcall. For the latter, you may use Renderer.SharedMaterial to restore drawcall batching after the color change effect has finished.
     
    Zimbres likes this.