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:
If you disable CM Brain’s debug text option and have no CM inspectors visible, then there should be no GC allocs.
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?
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?
Thanks for this ultrafast reply!
I’m not sure if I show you what you’ve requested.
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.)
It’s just the OnGUI in CinemachineBrain. This is present only in the editor. In builds, this is not present.
Thank you for this!