Search Unity

Does multiple cameras cause performance issues?

Discussion in 'Editor & General Support' started by Shayke, Mar 6, 2019.

  1. Shayke

    Shayke

    Joined:
    Dec 8, 2017
    Posts:
    352
    Hi, i am using 5 cameras for Parallax scrolling in my 2d game.
    Every camera has a different culling mask.
    Properties of the camera component:
    upload_2019-3-6_17-53-29.png
     
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    Adding cameras doesn't affect performance very much. What really matters is how many objects the cameras are rendering, because objects will be nearly twice as expensive to render if two cameras can see them. You should be fine if you're using culling masks and aren't applying post process effects per-camera.

    If you notice performance issues, you should check out your profiler.
     
    shacharoz and Joe-Censored like this.
  3. Shayke

    Shayke

    Joined:
    Dec 8, 2017
    Posts:
    352
    Thanks!
     
  4. 3dHomer

    3dHomer

    Joined:
    Jun 6, 2015
    Posts:
    14
    Actually, it doesn't seem to be true. Cameras may have a signnificant overhead even if they render nothing but a skybox (culling mask is set to Nothing). Seems like the culling mask is applied after other culling operations and Unity updates bounds of skinned meshes for every camera. I've tested it in a simple empty scene, just added 100 skinned characters and 10 cameras (with far distance 1 and culling mask set to "Nothing"). Every camera has an overhead.
    upload_2020-12-13_16-59-27.png

    It was reported as an issue but the ticket was closed with the resolution "By Design": https://issuetracker.unity3d.com/is...-culling-mask-does-not-intersect-the-renderer
     
    st-VALVe, SolidAlloy and Roman200333 like this.
  5. shacharoz

    shacharoz

    Joined:
    Jul 11, 2013
    Posts:
    98
    what if i have 1000 cameras that are turned off (component is off)?

    since it does not render anything, it might not affect anything, right?

    i do not see any influence on the Profiler even after i removed them?

    p.s. dont ask why i have 1000 cameras please, it was not my decision... i am just trying to optimize this :)
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    Then hurry to the profiler. Necro posting is not a way to solve performance issues. Nobody here knows the answer.

    DO NOT OPTIMIZE "JUST BECAUSE..." If you don't have a problem, DO NOT OPTIMIZE!

    If you DO have a problem, there is only ONE way to find out. Always start by using the profiler:

    Window -> Analysis -> Profiler

    Failure to use the profiler first means you're just guessing, making a mess of your code for no good reason.

    Not only that but performance on platform A will likely be completely different than platform B. Test on the platform(s) that you care about, and test to the extent that it is worth your effort, and no more.

    https://forum.unity.com/threads/is-...ng-square-roots-in-2021.1111063/#post-7148770

    Remember that optimized code is ALWAYS harder to work with and more brittle, making subsequent feature development difficult or impossible, or incurring massive technical debt on future development.

    Notes on optimizing UnityEngine.UI setups:

    https://forum.unity.com/threads/how...form-data-into-an-array.1134520/#post-7289413

    At a minimum you want to clearly understand what performance issues you are having:

    - running too slowly?
    - loading too slowly?
    - using too much runtime memory?
    - final bundle too large?
    - too much network traffic?
    - something else?

    If you are unable to engage the profiler, then your next solution is gross guessing changes, such as "reimport all textures as 32x32 tiny textures" or "replace some complex 3D objects with cubes/capsules" to try and figure out what is bogging you down.

    Each experiment you do may give you intel about what is causing the performance issue that you identified. More importantly let you eliminate candidates for optimization. For instance if you swap out your biggest textures with 32x32 stamps and you STILL have a problem, you may be able to eliminate textures as an issue and move onto something else.

    This sort of speculative optimization assumes you're properly using source control so it takes one click to revert to the way your project was before if there is no improvement, while carefully making notes about what you have tried and more importantly what results it has had.
     
  7. shacharoz

    shacharoz

    Joined:
    Jul 11, 2013
    Posts:
    98
    thanks for the tip :)

    but how do you know when you have a problem?
    i mean, what if you make a product for both web / pc or pc / mobile?
    would you test each platform separately?
    what if you have an assumption? such as - many useless cameras in the scene?

    second, how do you know if things influence the profiler or not?
    for example, if you get each frame rendered in 30ms in main menu and then in 10ms during a certain animation.
    how do i know if this is good or bad?