Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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:
    969
    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:
    969
    I see. Thanks!
     
  4. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    969
    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:
    969
    Cool! Thanks!