P
P
Pragma Games2021-06-06 19:10:35
Unity
Pragma Games, 2021-06-06 19:10:35

Why, after reactivating the object, Animator began to work incorrectly?

Good afternoon friends. An animator hangs on the object and plays animations.
At a certain point, the object becomes inactive [gameObject.SetActive(false)], after which the object is activated again [gameObject.SetActive(True)] , but the animation does not play correctly, the animator stopped responding to changes in the parameters. A simple example: There are two animations, the movement of the character to the left and to the right, the parameter float LookDirection is responsible for this, when it is equal to 1, the animation moves to the right, -1 to the left. Initially, everything works correctly, but after reactivating the object, character animations stop changing, ignoring the parameter passing.
The parameter is passed like this:
_playerAnimator.SetFloat("LookDirection", _lookDirection);
If we request values ​​via GetFloat("LookDirection"), we will see that the parameter is passed correctly, but switching between animations does not occur.

PS In many forums, this question has been repeatedly raised, but usually remained without a specific answer.

60bcf2aaf31d8148138461.png.

60bcf2bf8ba13482412401.png

60bcf2c93d975550282470.png

60bcf2d200c98679748069.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pragma Games, 2021-06-06
@PragmaGames

I suddenly found the answer. The solution is to save the animator settings after turning it off, I don't understand why it works, but it works. If someone understands how it works I will be glad to hear!

private void Start()
{
     _playerAnimator.keepAnimatorControllerStateOnDisable = true;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question