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

The correct method for loading a mesh for a custom gizmo

Discussion in 'Editor & General Support' started by IronHelmet, Aug 16, 2020.

  1. IronHelmet

    IronHelmet

    Joined:
    May 2, 2017
    Posts:
    85
    Can anybody help me set up the correct method for loading a mesh for a custom gizmo. I had a dumb solution working, but a number of team members had to delete their library and now the Resource.Load always fails.

    Code (CSharp):
    1.     void OnDrawGizmos()
    2.     {
    3.         if (gizmoMesh == null)
    4.         {
    5.             gizmoMesh = ((GameObject)Resources.Load("Ring")).GetComponent<MeshFilter>().sharedMesh;
    6.         }
    7.         Gizmos.color = Color.blue;
    8.         Gizmos.DrawWireMesh(gizmoMesh, transform.position, Quaternion.identity, gizmoScale);
    9.     }
     
    Last edited: Aug 17, 2020
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,894
    You could directly load a Mesh asset instead of a prefab with similar code, assuming the mesh is in Resources.