When switching between cameras why one of the cameras is keep stuttering for some time ?

At the top of a script I have this 3 cameras :

public CinemachineFreeLook standUpCamera;
public CinemachineFreeLook closeLookCamera;
public CinemachineFreeLook gamePlayCamera;

Inside Update() when loading a saved game I enable/disable the cameras in this order :

void Update()
    {
        // When starting a new game
        if (sceneName == "Game" && 
            MenuController.LoadSceneForSavedGame == false && newGameStart == false)
        {   
            SetCamerasAxisProperties(0);

            playerAnimator.Play("Stand Up");
            StartCoroutine(StandingUp());

            newGameStart = true;
        }

        // When loading a game (also when continue a game)
        if(sceneName == "Game" && 
           MenuController.LoadSceneForSavedGame == true && loadingGame == false)
        {
            newGameStart = true;

            Camera.main.GetComponent<CinemachineBrain>().m_DefaultBlend.m_Time = 0.1f;

            standUpCamera.enabled = false;
            closeLookCamera.enabled = false;
            gamePlayCamera.enabled = true;
            gamePlayCamera.m_XAxis.m_MaxSpeed = 300f;

            Camera.main.GetComponent<CinemachineBrain>().m_DefaultBlend.m_Time = blendingTime;

            loadingGame = true;
        }
    }

This is where I switch between the cameras :

standUpCamera.enabled = false;
closeLookCamera.enabled = false;
gamePlayCamera.enabled = true;

For testing and find the problem if I don’t switch between the cameras the active camera is the standUpCamera and this make the stuttering it’s not the player that stuttering but the camera.

When I switch between the cameras I see that the active camera is the standUpCamera than the gamePlayCamera but it’s taking few seconds before the standUp is enabled false and the gamePlaye become enabled true.

What I tried is to change the blending time :

Camera.main.GetComponent<CinemachineBrain>().m_DefaultBlend.m_Time = 0.1f;

standUpCamera.enabled = false;
closeLookCamera.enabled = false;
gamePlayCamera.enabled = true;
gamePlayCamera.m_XAxis.m_MaxSpeed = 300f;

Camera.main.GetComponent<CinemachineBrain>().m_DefaultBlend.m_Time = blendingTime;

First I set the blending time to 0 than back to the default (5)
But it didn’t help. I tried to set the blending also to 0.1f but it didn’t fix the problem.
Still it’s taking few seconds almost 3-4 seconds before the gamePlayCamera become enabled true and the standUpCamera enabled false. or maybe the blending is taking time.

Maybe I didn’t change the blending time as it should be ?

Try using priorities instead of enable/disable and use defined transitions between each camera

1 Like

Changing the priorities didn’t work much.

But this is working :

Camera.main.GetComponent<CinemachineBrain>().m_DefaultBlend.m_Time = 0.1f;

            standUpCamera.enabled = false;
            closeLookCamera.enabled = false;
            gamePlayCamera.enabled = true;
            gamePlayCamera.m_XAxis.m_MaxSpeed = 300f;

            StartCoroutine(FirstTimeBlendingCameras());

And

private IEnumerator FirstTimeBlendingCameras()
    {
        yield return new WaitForSeconds(0.1f);

        Camera.main.GetComponent<CinemachineBrain>().m_DefaultBlend.m_Time = blendingTime;
    }

Yes, you can’t change the blend time and then change it back all at the same moment, it will have no effect. Instead of changing the default blend time, why don’t you leave the default blend time and set up custom blends times for the specific cameras you are blending?

For example, here is a custom definition to cut when a specific vcam is activated:
7548601--932974--upload_2021-10-5_11-49-19.png

Alternatively, you can use CinemachineCore.GetBlendOverride which allows you to programmatically assign blends when transitions occur.

1 Like