Cinemachine Update Methods

Hi, Im Alejandro a programmer in my team and I’m doing right now a cameras system for the game.

I have implemented the Cinemachine for a third person camera and i have encountered a problem in the update system. For now you have the fixed update and the late update and neither methods work for us.

We know when we want the cinemachine cameras to implement their new state and it would be awesome to have a manual feature for this.
(As for now we are doing a workaround with a script with lower script execution order but we dont really like that solution)

Thanks.

@gulthuril Hello Alejandro,

Are you asking for an “update method” setting on each virtual camera?
Can I ask you to give some details about your situation, and why the current settings are not working for you, and what exactly you need it to do? It sounds like an interesting use-case.

Thanks,
Greg

The update method that would work the best for my team it could be a CinemachineBrain one.

The major problem we are encountering is that we have to apply some movements (a custom shake among others) to the camera after the Cinemachine did its thing. A public event like “onStateUpdated” that we can link our code could also work and it will be useful for HUD related stuff.

Also if you skip a frame or you do something to the camera even only one frame the smoothing of the transposer go a little crazy. We encounter some problems when we deactivate and then activate it later because it tries to smooth from the last state(and invalid one). Maybe it should reset the state when enabled/disabled?

Thanks for your time.

The best way to implement something like this is with the CinemachineExtension API. This allows you to make custom interventions to the camera transform within the pipeline, without having to worry about the Update method, or script ordering. Here is an example of a custom extension that offsets the camera by a fixed amount. It should point you in the right direction:

using UnityEngine;
using Cinemachine;

/// <summary>
/// An add-on module for Cinemachine Virtual Camera which post-processes
/// the final position of the virtual camera.
/// </summary>
[ExecuteInEditMode]
[SaveDuringPlay]
public class CameraOffsetter : CinemachineExtension
{
    [Tooltip("How much to offset the camera, in camera-local coords")]
    public Vector3 m_Offset = Vector3.zero;
    protected override void PostPipelineStageCallback (
        CinemachineVirtualCameraBase vcam,
        CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    {
        if (enabled && stage == CinemachineCore.Stage.Aim)
            state.PositionCorrection += state.RawOrientation * m_Offset;
    }
}

In fact the virtual camera does reset its state when disabled/enabled, so this sounds a little strange. Can you describe in more detail exactly what you are doing and the effect you are seeing?

1 Like

We will try to use that . However to control when Cinemachine is updated could be a good feature and also, as i said before, an event when the camera is updated would be useful.

We were debugging yesterday and it was in fact a problem in our code.

Thanks

We hear you. Thanks for the feedback!