Blending between cameras while game is paused.

Hi, I’m working on a strategy/management game. To zoom in and out I’m using a CinemachineMixingCamera to blend between 4 different cameras (Map, Far, Mid, Close). This works fine, as long as Time.timeScale is set to something above 0. Unfortunately, when Time.timeScale is set to 0, i.e. when the game is paused, the player can no longer zoom in/out.

What I’ve tried:

  • Setting UniformDeltaTimeOverride (CinemachineCore.UniformDeltaTimeOverride = 1f / 60 )
  • Manually calling InternalUpdateCameraState (mixingCamera.InternalUpdateCameraState(Vector3.up, Time.unscaledDeltaTime);

Thank you for your help!

7404356--905111--Screenshot_20210810_104646.png

Here is the code I use for updating the weights:

[Bind(Bind.From.ComponentInHierarchy, scene: Bind.SceneMain)]
public class CameraSimpleMixer : MonoBehaviour
{
    CinemachineMixingCamera mixingCamera;
    public float transition;
    public float factor = 1, exp = 1;
    public float mapCutoff = 0.025f;

  
    void Start()
    {
        mixingCamera = this.GetComponentNotNull<CinemachineMixingCamera>();
        StartCoroutine(UpdateRoutine());
    }

    IEnumerator UpdateRoutine()
    {
        while (this != null)
        {
            _Update();
            yield return null;
        }
    }
  
    void _Update()
    {
        CinemachineCore.UniformDeltaTimeOverride = 1f / 60;
        Debug.Log($"{Time.unscaledDeltaTime} [Time.unscaledDeltaTime]");
        if (mixingCamera != null)
        {
            if (transition < mapCutoff)
            {
                mixingCamera.m_Weight0 = 1;
                mixingCamera.m_Weight1 = 0;
                mixingCamera.m_Weight2 = 0;
                mixingCamera.m_Weight3 = 0;
            }
            else
            {
                mixingCamera.m_Weight0 = 0;
                mixingCamera.m_Weight1 = Val(1,0);
                mixingCamera.m_Weight2 = Val(2,0.01f);
                mixingCamera.m_Weight3 = Val(3,0);
            }
        }
    }

    [Pure] float Val(int v, float min)
        => Max(min, Clamp01(1 - Pow(Abs((transition - v) / factor), exp)));
}

The Mixing Camera update code is not dependent on deltaTime, so it surprises me that this is not working for you. Can you make a simple repro project that shows this issue and log a bug?

You are right. While failing to make a repro project I realized that I used Time.time instead of Time.unscaledTime in another place, so the value actually never changed. So the problem was on my end.

Sorry for blaming CM and thank you for your help! :slight_smile:

1 Like