Search Unity

Is there any way to perform Instanced Rendering in Edit Mode?

Discussion in 'General Graphics' started by jknight-nc, Sep 22, 2017.

  1. jknight-nc

    jknight-nc

    Joined:
    Jun 10, 2014
    Posts:
    52
    I am trying to call "Graphics.DrawMeshInstanced" in Edit mode by adding [ExecuteInEditMode] to a Monobehaviour that calls Graphics.DrawMeshInstanced from it's Update().

    It's not rendering anything.

    There are several other Instanced Rendering workflows. Like via CommandBuffers or via OnRenderObject etc.

    Is there any way to use Instanced Rendering in Edit Mode?
     
  2. jknight-nc

    jknight-nc

    Joined:
    Jun 10, 2014
    Posts:
    52
    Hey there,

    I did some more testing and exploration and found that Graphics.DrawMeshInstanced does work in Edit mode.

    I have got my system working now by calling Graphics.DrawMeshInstanced twice per batch, once to Camera.current (for scene view) and once using a reference to my game's camera.

    I had to add a specific call to the Renderer in OnSceneGui like so

    void OnSceneGui() {
    if (Event.current.type == EventType.Repaint) {
    InstancedRenderer.Instance.Render();
    }
    ...
    }

    And in order to redraw the game view from OnInspectorGui I had to set a bool to true and then add

    void OnSceneGUI() {
    if (doRedraw) {
    UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
    doRedraw = false;
    }
    }