Is there any way to reduce the garbage collection spikes on the CinemachineBrain LateUpdate? I am using it in combo with a FreeLook.
Thanks,
Pablo
Is there any way to reduce the garbage collection spikes on the CinemachineBrain LateUpdate? I am using it in combo with a FreeLook.
Thanks,
Pablo
Can you give some details of your setup? There shouldn’t be any GC going on at all.
I’m running into the same issue, and it took me a while but I finally figured it out!
The culprit was the CinemachinePostFX class. If you have UNITY_POST_PROCESSING_STACK_V1 defined in your project settings, then CinemachinePostFX class adds itself to the CinemachineBrain.sPostProcessingHandler. This handler expects your CinemachineBrain objects to have the CinemachinePostFx component on them, as well as every CinemahcineVirtualCamera object. If those objects don’t have that component, then this handler will spam GetComponent() every tick and cause the GC garbage.
So if you’re having the same issue that I’m having, try adding the CinemachinePostFx component to all your brains and virtual cameras and see if that helps.
I also noticed that the CinemachinePostProcessing class does almost the exact same thing as the CinemachinePostFx class, but it will only happen if you have UNITY_POST_PROCESSING_STACK_V2 defined in your project.
Personally I feel like CinemachineBrain and CinemachineVirtualCamera classes should have [RequiredComponent(typeof(CinemachinePostFx)] so others don’t run into this problem if they have these project defines set.
I hope this helps!
@brgishy Thanks for your detective work! This is actually a performance bug which has been fixed (for both PostProcessing V1 and V2) in the upcoming CM release. In the meantime, what you propose is an effective workaround.
hey @Gregoryl I’m running into the same problem still - was this supposed to be fixed yet?
I’m running Unity 2017.3.0p4, CM 2.1.10 and PPSv2 latest beta release.
Adding CinemachinePostProcessing extension component (There’s no CinemachinePostFX anymore?) to my Vcam doesn’t really fix it:
This is profiled on an Android tablet
This has been fixed in the latest CM 2.1.12, but that is available only with Unity 2018.1.
If you’re not ready to upgrade, PM me and we’ll figure something out.
I still get GC every frame from cinemachine 2.1.12 in 2018.1.0f2
Not as bad, but still there.
Never had post processing stack v1 in this project, but do have v2
-edit-
full profile
It’s the CineMachine Free Look camera.
I believe the offending code is from CinemachineBlend.cs, Line 33
public float BlendWeight
{
get
{
if (BlendCurve == null || BlendCurve.keys.Length < 2 || IsComplete)
return 1;
return Mathf.Clamp01(BlendCurve.Evaluate(TimeInBlend / Duration));
}
}
BlendCurve.keys seems to generate garbage every frame.
@tertle thanks for the investigative work!
The line in question should have read: if (BlendCurve == null || BlendCurve.length < 2 || IsComplete)
This error has been fixed on the CM trunk, and the updated version will be available in preview soon.
Thanks for reporting, we really appreciate it.
Sorry to bring this post back, but I wanted to ask if this issue was solved by that time with new versions. In a mostly blank project, I’m having lag spikes (apparently by RenderCamaraStack
), but I noticed that the CinemachineBrain.LateUpdate()[Invoke]
is allocating 336B of GC every single frame.
EDIT: Apparently this only happens in the editor if you have the “Show Debug Text” on. For more information check this thread . I apologize I didn’t do proper research regarding this issue.