How to Graphics.DrawMesh in Editor (SceneView)?

Hi,
i’m trying to create a tool that ideally is able to display meshes at editor time the same way it does at runtime. At runtime it uses Graphics.DrawMesh() in Update(), no problems there. But i tried everything i can think of to make it work at edit time too. ExecuteInEditMode doesn’t reliably call Update(), OnRenderObject() seems to take it, but somehow buffers the draws up and the editor gets slower and slower until it becomes unusable in about 10 seconds (bug or intended?) i tried keeping lists of rendered objects through OnRenderObject() to not redraw them, but unity clears the draws from the scene under certain circumstances like a random Update()s, so it flickers when something is moved in the scene (and it still buffers up a few times), so that didn’t work well.
DrawMeshNow() with Material.SetPass() works ok but doesn’t include lighting (so it looks different at runtime) and worse, it somehow renders my custom shader completely wrong if i add a pointlight (only in DrawMeshNow(), i’ve compared it with built in shaders but couldn’t find a magic switch).
Subscribing to EditorApplication.update has the same buffering problem as OnRenderObject(), EditorApplication.delayCall too. OnDrawGizmos() can only use DrawMeshNow(), InternalEditorApplication.Set/RemoveCustomLighting() doesn’t do anything, Gizmos.DrawMesh is completely different and not applicable for what i want etc…
So, i’m out of ideas.
How can i use DrawMesh() at editortime, or is there an equivalent method to draw meshes (something like the detailmesh/grass drawing from the builtin terrain)?

Edit: tried OnSceneGUI() too, and it also didn’t work great/buffered up (even with if(repaintevent))

There’s no way then? I’d like to not need to resolve to creating gameobjects as this would hurt performance for my case.

It appears you can make it render in the editor and the game using graphics.DrawMeshInstanced but with 1 instance

1 Like

interesting, will try that. thx

Hi!
I am also looking for a way to draw meshes in edit mode. Have you been able to figure it out? Did the suggestion about Graphics.DrawMeshInstanced work?

Yes, it did work, but there’s a better way: Graphics.DrawMesh in Editor - Unity Engine - Unity Discussions

1 Like

For some reason it did not work for me if I supplied the camera to the DrawMesh calls, but I have managed to get a good-enough solution based on the earlier post in the thread you linked and with this: http://answers.unity3d.com/answers/1371136/view.html

2 Likes

Neither of these solutions work for me. I’m using Unity 2018.3, have there been changes to the API? Is there any new solution?

2 Likes

Anyone? :stuck_out_tongue:
edit: nvm figured it out. The default PresentationSystemGroup runs at the right time if you add systems to that and then render in those systems it’ll work fine. The issue was delegate update runs after the scene is rendered.

This is paradise level of comment.