Been struggling with this for a while now. I need to draw a mesh using Graphics.DrawMesh, not Graphics.DrawMeshNow as I want lighting information.
The problem is “Update” is only called when the scene changes. As a result, my mesh disappears under certain situations, like:
- Losing application focus: e.g: toggling between Unity and Visual Studio.
- Randomly after script reloads
- Focusing on an object, sometimes unity clears graphics when doing this but doesn’t call Update after.
I know I can’t use: OnRenderObject, DrawGizmos, EditorApplication.update. Because these are called many times before unity actually performs scene rendering. Drawing a mesh in OnWillRenderObject crashes Unity.
So my question is: How can I tell Unity to render the scene, or clear the graphics in edit mode?
As an example, imagine a cube that is rendered in-front of the scene camera that needs to react to light. In order to do this, I need an event that updates frequently, has access to Camera.current and only draws before the scene is about to be rendered. The object/script responsible for drawing cannot be added to the camera. The object/script cannot be made dirty when the scene camera moves: i.e don’t modify the scene in any way.
I think this scenario is impossible with Graphics.DrawMesh. But just wanted to check if there is a possible solution. I might be able to try CommandBuffers, but that’s a whole other beast, especially if you want Cast/Receive shadows.
The endless struggle continues…