Search Unity

FindMainCamera from Profiler.CollectUIStats

Discussion in 'General Discussion' started by BeyondMASC, May 21, 2020.

  1. BeyondMASC

    BeyondMASC

    Joined:
    Feb 11, 2019
    Posts:
    9
    Hi,

    The question is;

    This particular process is only generated for profiler purpose or I need to fix it?

    Because those calls increase proportionally with the number of UI elements shown on screen.

    Thanks, cheers!

    Find Main Camera in PROFILER.png
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,457
    This is only generated when one of the UI Profiler Modules is active. You can disable these modules in the ProfilerWindow or call Profiler.SetAreaActive(ProfilerArea.UI, false) and Profiler.SetAreaActive(ProfilerArea.UIDetails, false) to avoid this overhead.

    Although I do have to admit that >1ms per FindMainCamera is a bit crazy. Do you happen to have multiple cameras or some other GameObjects tagged as MainCamera?
     
    BeyondMASC likes this.
  3. BeyondMASC

    BeyondMASC

    Joined:
    Feb 11, 2019
    Posts:
    9
    Thanks for your response.
    By your answer I definitely will need to look for something wrong somewhere.
    Appreciated.
    God bless.
     
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,457
    Just to be clear, as long as you don't use Camera.main anywhere you're likely gonna be fine. I'm not sure why the UI Profiler would call it 17 times unless there's 17 canvases and even then I'd assume it could cache the one main camera. So you might want to file a bug report for that (and ping the issue I'd here)
    But as a workaround, disabling the UI Profiler Modules should get you profiler results without that overhead and it won't be there in release builds either.
     
    BeyondMASC likes this.