Search Unity

Feedback CinemachineBrain.OnGUI generates 368 bytes of GC allocation every frame

Discussion in 'Cinemachine' started by BardoDev, Jul 2, 2022.

  1. BardoDev

    BardoDev

    Joined:
    Oct 10, 2016
    Posts:
    8
    I've been fixing some garbage collection problems in my project and I came across this one that is out of my control. The GC allocation doesn't appear to be coming from OnGUI, but upon removing the CinemachineBrain component from the camera it stops generating garbage.
    I know the code is wrapped by a #if UNITY_EDITOR and this specific issue doesn't occur on a build, but this along with other unity APIs have been generating a total of 5Kbs of GC Allocation every frame and every time the collector hits, the frame rate drops dramatically making the testing experience unpleasant and forcing me to make a build to get an actual sense of the game's optimization.
    Profiler:
    upload_2022-7-2_13-40-44.png
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    If you disable CM Brain's debug text option and have no CM inspectors visible, then there should be no GC allocs.

    upload_2022-7-4_15-31-15.png
     
  3. buc

    buc

    Joined:
    Apr 22, 2015
    Posts:
    123
    I still get these GC allocs, just by adding the CinemachineBrain to the MainCamera in a fresh scene and have the "Show Debug Text" disabled (also tried with disabling the other checkboxes).

    Unity Version 2021.3.19f1, which is at the moment the latest LTS and recommended version.
    Cinemachine version is 2.8.9

    And I do not see any other versions in the package manager, even with "Enable Pre-release Packages" turned on.

    Are these GC allocs only in editor and will vanish in the build?
    Which version works as you have mentioned and how can you install another version?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    As far as we know, Cinemachine does not generate GC allocs every frame. Can you run deep profiling and show where the mem is being allocated?
     
  5. buc

    buc

    Joined:
    Apr 22, 2015
    Posts:
    123
    Thanks for this ultrafast reply!
    I'm not sure if I show you what you've requested.
    GCAllocs.PNG

    So this happens when I just add the Cinemachinebrain and when I remove the Component, the GC allocs vanish.
    I've also tried to have a simple lookat case with 1 virtual cam looking at a cube (in order to exclude cases where it doesn't function when not has something to do, like lookat, follow, etc.)
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    It's just the OnGUI in CinemachineBrain. This is present only in the editor. In builds, this is not present.
     
    buc likes this.
  7. buc

    buc

    Joined:
    Apr 22, 2015
    Posts:
    123
    Thank you for this!