Cinemachine Recentering

Hello, I am looking to implement a button that will recenter the Cinemachine camera behind the player character. I have a camera controller script that runs the following function on a CinemachineOrbitalFollow component’s axes
I’m using Cinemachine 3.1.2

 private void RecenterAxis(InputAxis axis)
 {
     var recentering = axis.Recentering;
     recentering.Enabled = true;
     recentering.Wait = 0;
     recentering.Time = span;
     axis.Recentering = recentering;
     //axis.Recentering.Time = span;
     //axis.Recentering.Wait = 0;
     //axis.Recentering.Enabled = true;
     Debug.Log("Recentered.....");
 }

I have tried several permutations of the above code, creating a new instance of the Recentering struct and setting it, setting the items individually but none of the changes seem to take effect. I’ve also tried setting these values and calling “TriggerRecentering” On the axis. I’ve also cut down from doing all 3 axes at once to a single axis, but none of these has worked.

If I manually enable/disable the recentering from the inspector, things work as expected and the camera recenters nicely, but if I try to trigger the change from this script then nothing happens. I do see the “Recentered” message in the debug log as well so I know the code is being run.

I marked this as a bug since it seems like there is something not quite aligning with what the expectations are for these functions, but it could also be user error. Any help or guidance on how to get this working would be greatly appreciated. Please let me know if I can supply any more information. Thanks!


Sorry for the delayed response, this post dropped off my radar!

The reason it’s not working is that InputAxis is a struct, not a class, so it gets passed by value. Your code is changing only the local copy, so it has no effect on the source.

Change your method’s signature to private void RecenterAxis(ref InputAxis axis) and that way you’ll pass a reference to the appropriate axis rather than a copy.

No worries! Its busy and things happen, I appreciate you getting back to me. I made the changes and it works as expected. I knew it had to be something simple I was overlooking, :man_facepalming: at least I know next time I run into something like this. Thank you for your help!