Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

How do you tint a MeshInstanceRenderer?

Discussion in 'Graphics for ECS' started by davenirline, Jul 20, 2018.

  1. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    1,009
    I'm just making a grid of tiles where I could change their tint on click. However,
    MeshInstanceRenderer is a shared component data so it affects every other entity that uses it. Is there another way to render that does not use MeshInstanceRenderer?
     
  2. vitautart

    vitautart

    Joined:
    May 3, 2018
    Posts:
    29
  3. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    1,009
    I see. Thanks!
     
  4. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    1,009
    Uhm, how do I set the color exactly? From the documentation, it needs MeshRenderer so it can call SetPropertyBlock().
    MeshInstanceRenderer doesn't have such method.
     
  5. vitautart

    vitautart

    Joined:
    May 3, 2018
    Posts:
    29
    Hm, It is more complicated that i thought. Sorry.
    Maybe for your use case it is better to use simple substitution of tiles with different materials, if it's possible.

    But if you want shader approach, i found this post https://forum.unity.com/threads/can...r-instance-data-and-custom-draw-order.534714/
    It seems you can write your own MeshInstanceRenderer, or modify existing one, or wait until developers improve their MeshInstanceRenderer API. You can find MeshInstanceRendererSystem.cs in packages folder of your project, and it has this line of code that does all job
    Code (CSharp):
    1. Graphics.DrawMeshInstanced(renderer.mesh, renderer.subMesh, renderer.material, m_MatricesArray, length, null, renderer.castShadows, renderer.receiveShadows);
    null parameter is for MaterialPropertyBlock
     
  6. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    1,009
    Cool! Thanks!