- I’m working on an editor tool which needs to draw hundreds or thousands of nodes.
- I need the nodes to be 3D meshes, and I need them to render with proper occlusion by other scene geometry.
- I don’t want these nodes to be game objects. They only exist when editing the node mesh for visualization purposes.
When you call Graphics.DrawMeshNow within OnSceneGUI, it seems to add the mesh to some kind of buffer, yet it never clears this buffer. The result is, the editor gets progressively slower and slower until it becomes completely unusable. For a better explanation of what’s going on, see this question on Unity answers. I have found no way to clear this mesh buffer.
When you call Graphics.DrawMeshNow within OnDrawGizmosSelected, it does not be have this way. The meshes are drawn just once per update and it maintains a very fast frame rate. However, drawing the meshes in OnDrawGizmosSelected has the serious drawback that the meshes are drawn AFTER OnGui as seen here.
In my editor tool, I have a toolbox that is shown in the main scene view when you’re editing. If I draw in OnDrawGizmosSelected, the nodes cover up the toolbox. Not going to work.
Graphics.DrawMeshNow instructs you to call it within OnPostRender in a script attached to your camera. Well, that’s great for in-game use, but there’s no way to attach a script to the scene view camera in the Unity editor. I can find no way to hook into the scene view’s camera’s OnPostRender function to make my calls there. Not going to work.
The alternative, Graphics.DrawMesh (whish is a delayed render) seems to work within OnSceneGUI as intended, BUT it has the MAJOR drawback that it is vastly, vastly slower than Graphics.DrawMeshNow when drawing with a material. (All the versions of this function that don’t require a material to be set are deprecated.) Its so slow that it becomes a slideshow with only a few hundred nodes. Not going to work.
So is this behavior of DrawMeshNow within OnSceneGUI a bug? Or if its intentional, is there a way to clear this seeming mesh buffer?