Search Unity

Question Conditional Rendering of many meshes with Graphics.RenderMesh()

Discussion in 'Scripting' started by Fly81, Feb 9, 2024.

  1. Fly81

    Fly81

    Joined:
    Oct 6, 2021
    Posts:
    34
    Hi,

    I am rendering a lot of meshes in the editor environment (not runtime) with
    Graphics.RenderMesh
    in the
    SceneView.duringSceneGui
    callback. So many to the point where the SceneView starts lagging when moving/panning/zooming the camera.

    I noticed, that the drawn mesh does not disappear immediately, when the RenderMesh function isn't called any more, so I tested calling RenderMesh only every 100th, 1000th, 10.000th time like so:

    if (c++ % 1000 == 0) Graphics.RenderMesh(new RenderParams(), mesh, 0, Matrix4x4.identity, null);


    I expected the mesh to flicker but to my surprise the mesh was on screen continuously, even when moving the mouse over the SceneView (triggering the duringSceneGui callback). On top of that the lagging stopped because the rendering only happened every Xth time.

    My question is: How can I consistently enforce this behaviour of the meshes being cached? Is there some setting in a renderer, or can I hook into the SceneView camera or something. A hint in the right direction of where to look would be much appreciated!