Objects jitter when using parent constraints with Cinemachines

I’m having lots of trouble getting objects that are Parent Constrained to a Cinemachine camera to move smoothly.

I’ve been able to reproduce this problem both with “multi-parent” constraints from Unity’s Animation Rigging package, as well as regular Parent Constraints.

The repro is fairly simple:

  1. Create a new scene with a GameObject (“MainCamera”) containing a Camera component.
  2. Give “Main Camera” a Cinemachine Brain component.
  3. Create a new GameObject (“CinemachineCamera”) containing a Cinemachine Camera component, and a Pan Tilt component.
  4. Create a new 3D Sphere Object (“Sphere”).
  5. Set the “Sphere” transform’s Z axis to 5 or so, so it’s in frame of the CinemachineCamera.
  6. Give “Sphere” a Parent Constraint component, add “CinemachineCamera” as the source. Activate the constraint.
  7. Press play.
  8. Observe the following behavior when moving the camera: Imgur: The magic of the Internet

I’ve tried messing with the update mode – “LateUpdate” does nothing, “FixedUpdate” fixes it, but then the camera is on fixed update which makes the entire game feel jittery (this is my main camera in an FPS game).

Here’s what the non-minimal repro looks like, for context: Imgur: The magic of the Internet

Any help would be super appreciated. Thank you!

That’s because the CM camera is updated very late in the frame - after the parent constraint has done its thing. So what ends up happening is that the constraint is using a stale camera position from the previous frame.

The solution is to not use parent constraints. Instead, whenever you have anything that depends on the camera’s transform, hook into CinemachineCore.CameraUpdatedEvent to invoke a piece of code that can do what you need. It’s guaranteed to be called after the camera has been positioned for the frame.

And incidentally, it’s better to read the main camera’s position rather than the CinemachineCamera’s. CameraUpdatedEvent will pass you the CM Brain, from which you can get the transform or the Camera component if you need to access lens info.

1 Like

Amazing, this is exactly what I was looking for!

Now my only problem is in getting my animation rig to evaluate after the cinemachine camera has updated (looking for tips on this problem here: Manual Evaluation doesn't work - #12 by Avald).

But at least this gave me an avenue to explore – and I can confirm that this has fixed my simple case with the parent constraint!

1 Like