Get Input while Time.timescale == 0?

Hey,

I want to controle my pausemenu by keyboard input but Time.timescale is set to 0 for pausing the game. Is there another way to perform keyboard input based events than using the updatefunction?

You can also use the Input.GetAxisRaw method, which will work even when timeScale = 0.

Active components should still get Update() calls while time is frozen, but bear in mind that Time.deltaTime will always be zero (this can cause funky behavior if you’re not expecting it). If it’s not being called, your component is probably missing or inactive.

It’s simple enough to test if Update() is getting called by putting a simple log statement in there.

GetAxis uses Time.deltaTime to smooth the value by Sensitivity/Gravity settings from the Input configuration, therefore it respects Time.timeScale. You can use GetAxisRaw, but that will no longer respect Sensitivity/Gravity. This will apply smoothing using Time.unscaledDeltaTime, but it might produce different results, not sure exactly how GetAxis resolves.

private void GetSmoothRawAxis(string name, ref float axis, float sensitivity, float gravity)
{
    var r = Input.GetAxisRaw(name);
    var s = sensitivity;
    var g = gravity;
    var t = Time.unscaledDeltaTime;

    if (r != 0)
    {
        axis = Mathf.Clamp(axis + r * s * t, -1f, 1f);
    }
    else
    {
        axis = Mathf.Clamp01(Mathf.Abs(axis) - g * t) * Mathf.Sign(axis);
    }
}