Search Unity

Question animator.SetFloat not working after game is paused

Discussion in 'Animation' started by OliverWithAnO, May 15, 2023.

  1. OliverWithAnO

    OliverWithAnO

    Joined:
    Sep 24, 2022
    Posts:
    4
    Hello,

    I have a Set Float call which uses the dampening and delta time perameters, When I pause the game (as in changing the time scale to 0), and unpause the game (setting it back to one), the set float now does not work, the blend tree it controls is acting as if it were always on 0.

    I understand that when timescale is 0, so is delta time, therefore the result of the set float would be 0, but after its unpaused, delta time goes back to normal, but the set float function does not. Whats even weirder is that the same things happening when i use unscaled delta time or even just the value of one.

    I have a fear the function is flawed but i don't know how to get around that.

    Here's the code:

    Code (CSharp):
    1. if(Time.timeScale != 0) //the if statement was an attempt to debug
    2.         {
    3.             player.animator.SetFloat("Speed", Mathf.Abs(speed), 0.05f, Time.deltaTime);
    4.         }
    Code (CSharp):
    1. public void Resume()
    2.     {
    3.         Cursor.visible = false;
    4.         Cursor.lockState = CursorLockMode.Locked;
    5.         PauseMenuUI.SetActive(false);
    6.         Time.timeScale= 1f;
    7.         paused = false;
    8.     }