Search Unity

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

Question How to draw mesh in scene view

Discussion in 'Universal Render Pipeline' started by Qriva, May 22, 2021.

  1. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    I am developing the tool (editor window + editor tool) and I need to draw mesh in scene view window - sounds like trivial task, but I can't find the way to make it work. I checked google and there are multiple similar questions, but there are no working solutions.

    There is no method in Handles to draw mesh, Gizmos can be used only in OnDrawGizmos, I can't find any extra utility, literally the only method is Graphics.DrawMesh. The problem is that mesh persists longer than one frame.
    I need to draw some kind of "brush" preview, and when mouse moves this preview should follow the cursor, but currently it adds another preview every frame, while the previous one is still there until I press mouse (or somehting cause refresh, whatever causes it).
    I tried to call Repaint(), EditorUtility.SetDirty(), EditorApplication.QueuePlayerLoopUpdate(), but then the rendered mesh is blinking and when I stop moving the cursor it just disappears.

    What is the solution? I do not believe there is no reliable way to paint mesh in scene view.
     
    Propagant likes this.
  2. Propagant

    Propagant

    Joined:
    Nov 18, 2013
    Posts:
    32
    My solution was to create a regular primitive gameObject, assign it to the static field and I could just play around with regular gameObject. Once I was done, I called DestroyImmediate for the object.