Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

Resolved Graphics.DrawMesh cannot set color with material

Discussion in 'General Graphics' started by glorog, Apr 5, 2021.

  1. glorog

    glorog

    Joined:
    Apr 5, 2021
    Posts:
    2
    Hi, I'm stuck with graphics, Idk what I'm missing...

    Inside OnDrawGizmos, outside playmode I'm trying to draw mesh:
    Code (CSharp):
    1. mat.SetColor(ColorProp, Color.red);
    2. Graphics.DrawMesh(mesh, Matrix4x4.identity, mat, 0);
    Why after those 2 lines I still having basic grayish color for mesh?
     
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    9,354
    Try setting the color to a material property block and then supply it with your DrawMesh command.
     
  3. glorog

    glorog

    Joined:
    Apr 5, 2021
    Posts:
    2
    @up I wasn't confident to use it, because I couldn't find how to use MPB with DrawMesh. Apparently I can just create it and don't have to feed it with GetPropertyBlock like in Renderer.
    It works! Thanks
     
unityunity