Search Unity

Question Camera.Render causes unnecessary UI rebuilds and performance issues

Discussion in 'UGUI & TextMesh Pro' started by swarzzy56, Dec 3, 2021.

  1. swarzzy56

    swarzzy56

    Joined:
    Jul 17, 2020
    Posts:
    1
    Hello. In one of the projects that I am working on, We have a complex scene with a lot of UI and 3D stuff which are rendered to UI viewports through Raw Images. For implementing some of the rendering features we heavily rely on Camera.Render method for rendering cameras on-demand or to ensure the correct rendering order without a need to struggle with cameras depth values.
    I noticed, that when I call Camera.Render, some heavy UI rebuilding logic happens for each call. Camera.CustomRender invokes UIEvents.WillRrenderCanvases which does some heavy UI rebuilding stuff even though all UI in the scene has Screen Space Overlay mode and none of the UI is rendered to that camera.
    I actually tried to slightly change the rendering code so it does not call Camera.Render but does the tricky work of syncing cameras "enabled" states and correct rendering order. When the camera is rendering automatically, no UI rebuild appears.
    Безымянный.png
    On IPad 2019 (7th generation) these rebuilds consume about 1-2 ms each. Given that application might have up to 3 viewports with custom rendering this yields unacceptable performance costs.

    All UI in the scene is static at that moment and actually, no UI rebuild should occur.
    Screenshot_2.png

    This Camera.Render method is actually important for us, since removing it will lead to a significant increase in code complexity. So I am looking forward to any help or advice