Search Unity

GameObject Disable Resets Animator But Transform Parameters Remain At Interrupted Animation State

Discussion in 'Animation' started by nikulude, Oct 4, 2018.

  1. nikulude

    nikulude

    Joined:
    Nov 29, 2017
    Posts:
    13
    I got the following problem and it really drives me insane - I can not imagine that there is no solution to this,

    Google didn't help me so far so here I am hoping to get help by the community or unity devs:

    I got an enemy represented by a parent object and lets say two child objects, Animator attached on the parent. There are at least two animations in the state machine where rotation and position of child objects are altered - think about moving hands up and down and moves for shooting and jumping. And I am of course using an enemy pool, which means when enemy hit -> disabled, when enemy of same type needed - get it from pool and reenable. So far so good.

    Now imagine the enemy is in the middle of the first animation and gets hit = disabled and stored in the pool. When I reenable him, the Animator is reset but child transforms remain in the state from the middle of the "interrupted" animation, when the enemy was disabled. So in the default state, when hands are not being moved one of the hand is half up, other half down instead both hands down. How to reset the "default" state? Everything reset through script, where all possible child transform parameters like position and rotation are reset to the default values? What is when I have a complex object containing multiple layers and 50 child transforms that are bein altered in animations?!..

    Is there any plausible solution to this (seemingly trivial) problem?

    Thanks!
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    I submitted a bug report about something similar - specifically, the ways this behaviour is different from the Playables API and how neither system gets it quite right. That was almost half a year ago and I haven't heard anything after the initial "yep that's a bug".

    There's also this thread which doesn't really have a solution either: https://forum.unity.com/threads/write-defaults-confusion-bug.392058/.

    The only way I found to ensure the models are properly reset for pooling is to use my Animancer plugin (or presumably anything using the Playables API) and manually call StopAll then Evaluate before deactivating the object. It can't be automated in OnDisable, it has to be before the actual SetActive(false) call. And trying to do the same thing in Mecanim had no effect.

    That was in 2018.1 and I have no idea if this behaviour has been fixed or altered since then.