Search Unity

Animator default values can change through the animations itself

Discussion in 'Animation' started by Johannski, Dec 21, 2017.

  1. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    I had a lot of trouble with my decision to use the animator for ui, a lot of unexpected strange things happened. Today I finally took the time to find out why: The default values are defined every time the animator is enabled, so when the runtime controller is created. This does make sense from the design decisions the unity team made. The problem now is, when you disable the animator, it does not write those default values back into the animator. So the values from the active animation at the time of deactivation define the new default values.
    Here is a simple video to show this behavior (the bottom text is visible by default, but once the gameobject was disabled while the text is disabled the default value will become disabled as well).


    Does this bother anyone else or am I the only one who thinks that is not logical (with the knowledge that all states in the animator are resetted when disabled and even the runtime controller is created from scratch every time the animator is enabled).
    Is there any way to set the default values for the game object when the animator is disabled? That would be my expected behavior solution.
     
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    This is beyond my knowledge - but the logical reason given to do this is to free up the resources. I think this is one of the reasons given to similar questions asked before.
    Cant you capture the values upon or just prior to disabling and apply those values upon reenabling - via script?
     
  3. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    I didn't find any interface to get the default values that have to be stored somewhere. As for freeing resources. I'm totally with you, not everybody probably needs that feature, so it would be annoying to create an overhead for them. My suggestion is to not store the values while being disabled, but to apply the values right before the object is disabled, the time the information is discarded.

    Anyways, I got a response from unity, that they were able to reproduce the problem and sent it to their developers. Let's see what they think :)
     
    ModLunar and theANMATOR2b like this.
  4. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    I think this can only be accomplished via code. Sorry to send you astray. Good to know Unity Devs are looking at it. I remember mecanim_dev explaining the reason for this - or something very similar.
     
    ModLunar likes this.
  5. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
  6. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    I'm not sure about which topic you are talking about.

    For the problem you got, it look like a bug because the animator must write back the default values when it get disabled otherwise the behaviour would be undeterministic.

    Our QA seem to have repro your issue so your bug should be on his way to our bug list.
     
    ModLunar and theANMATOR2b like this.
  7. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Ah cool! That's good news. I thought that it maybe was your intention to not write the values back once the animator is disabled.Because I thought that I was asking so cautious, because I know that it is not easy to change something a lot of people have adapted to. Anyways, thanks for your update, looking forward to any progress that will come up :)
     
    ModLunar and theANMATOR2b like this.
  8. Talgame

    Talgame

    Joined:
    Oct 19, 2015
    Posts:
    5
    Hi, is there any news about this problem? It's terrible bug I don't understand how people do pooling of animated objects, like enemies if this bug exists
     
    ModLunar likes this.
  9. poliman

    poliman

    Joined:
    Feb 5, 2015
    Posts:
    29
    I run to this problem, but when deactivating object (not animator) that has simple animation (with Anima2D bones) and animation is let's say in half of the animation progress,
    the values that the object had at the time of deactivating, are writen as defaults.

    When you activate object again, deafault values are the ones that were set by animation at the time of deactivating.

    Anything new about this issue?
     
    AlternativeShit and ModLunar like this.
  10. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Hey there,

    I got a quite extensive response:
    So it is by design and you and trick it by for example switching to another state (not empty) right before disabling the go.
     
    Last edited: Feb 25, 2019
  11. Tortuap

    Tortuap

    Joined:
    Dec 4, 2013
    Posts:
    137
    Too bad that there is not simply a property like Animator.AutoWriteDefaultValuesOnDisable.

    Doing it manually require specific code everywhere you disable your game object, so any generic code or third party code that does that is forbidden. And its a real pain to maintain.

    Doing it from method OnDisable of a component aside Animator requires your component to be ordered before the Animator component (your OnDisable must be called before Animator's OnDisable because it would clear stored values before you would try to write them back).
     
    AlternativeShit and ModLunar like this.
  12. MrBIoBR

    MrBIoBR

    Joined:
    Jul 2, 2017
    Posts:
    9
    I'm running into a similar issue.

    is there a way for me to "override" the default values by code? you said "doing it manually requires specific code" how do you manage to do it?
     
    AlternativeShit likes this.
  13. AlternativeShit

    AlternativeShit

    Joined:
    Feb 17, 2021
    Posts:
    18
    I ran into the same issue, I find it odd that it's so overlooked by the team...
     
  14. aesi_aes

    aesi_aes

    Joined:
    Dec 16, 2013
    Posts:
    17
    Jepp same here :)
     
  15. forestrf

    forestrf

    Joined:
    Aug 28, 2010
    Posts:
    231
    Same here, I wish there was Animator.AutoWriteDefaultValuesOnDisable.
     
  16. anthonov

    anthonov

    Joined:
    Sep 24, 2015
    Posts:
    160
    I ran into this issue,

    Code (CSharp):
    1. animator.keepAnimatorControllerStateOnDisable = true;
    2. animator.WriteDefaultValues();
    short recap with 2 solutions, 1 is auto, 2 is manual.
     
    Last edited: May 14, 2022
    BMRG14 likes this.
  17. MaximPP

    MaximPP

    Joined:
    Jan 26, 2019
    Posts:
    76
    Same problem. I want checkbox WriteDefaults to be False by default
     
  18. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    224