Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Animator locking animated value even when current state has no curves/keys for that value

Discussion in 'Animation' started by stregillus, Nov 10, 2016.

  1. EternalSouls

    EternalSouls

    Joined:
    Apr 22, 2021
    Posts:
    3
    Hey There, I was trying to fix this feature to our game and finally I understood how it should work. I didn't like the version of disabling the Animator component; the reason why it didn't work is that if your Animator is in an empty state or doesn't do anything at all it is acting like "Write defaults" is on. so in that case you have to use discrete states, and always have an active one.

    So here is what I did: Create all possible states of your character in animator, then activate each state as the character state changes, so that unity animator knows in what state your GameObject is in any given time; Create transition states if you need to, between two scenes;
     
  2. Hipnos

    Hipnos

    Joined:
    Dec 24, 2019
    Posts:
    2
    This, this right here did the trick for me, you can even turn it On in the Animator component of your GameObject through the Debug view in the inspector.
     
    angelonit likes this.
  3. greenlittleapple

    greenlittleapple

    Joined:
    May 6, 2014
    Posts:
    1
    I just wasted 3 hours trying to figure out why my property wasn't updating while in a totally unrelated animation. This is a horrible, HORRIBLE "feature" that desperately needs to be removed. I am appalled that the developer has offered no solutions and instead poses it as intended behavior instead of fixing it.
     
    Boodagames and april_4_short like this.
  4. javaduan

    javaduan

    Joined:
    Mar 15, 2017
    Posts:
    4
    Why is this still no fixed?
     
    AldeRoberge likes this.
  5. chichichap

    chichichap

    Joined:
    May 28, 2017
    Posts:
    15
    This is so stupid and counter-intuitive.

    Even if the animator state is in an empty state with Write Defaults off, it's still locking all properties.
     
  6. jlavoinegsn

    jlavoinegsn

    Joined:
    Oct 29, 2015
    Posts:
    2
    Also was spinning my wheels on this. I found that making sure "Write Defaults" was OFF on the animator state that was playing/hijacking properties fixed it for me (on unity 2020.3).
     
    Strogman likes this.
  7. agnis16

    agnis16

    Joined:
    Aug 1, 2018
    Posts:
    3
    This was at the top on google.
    I was frustrated several times with this but I might have found a stupidly simple solution.
    Animation window's "Preview" toggle button is THE solution at least for me.
     
  8. Holydh

    Holydh

    Joined:
    Nov 17, 2016
    Posts:
    4
    Same issue here. I'm working on some security cameras animation. I have to make them smoothly rotate with the look at function while keep having some idle animations going when they spot the player. I'll have to script all things manually and disable the animator completely then because of that. : /
    A function to just disabling the animator handling of transform and rotations would have been really nice.
     
    Loumiskme and ModLunar like this.
  9. shibi2017

    shibi2017

    Joined:
    Jan 18, 2018
    Posts:
    153
    l
    Lateupdate no use.
     
  10. OleksandrMartysh

    OleksandrMartysh

    Joined:
    Dec 13, 2015
    Posts:
    25
    The year 2022 is passing, this bug is still there.

    OMG! Why are you doing this to us Unity team?
     
    shibi2017 likes this.
  11. Grafos

    Grafos

    Joined:
    Aug 30, 2011
    Posts:
    231
    Wait, WHAT? This is such a basic, obvious thing. I had spent several hours last night trying to figure out why some shader properties on my Boss enemy refuse to change through script, and it suddenly hit me "Is it because I animated them in the Boss Cutscene? Could it be that these properties are locked now?". "Nah, that can't be it, that 'd be too stupid!" And yet... here we are...
     
    Last edited: May 24, 2022
  12. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    628
    Still needs a fix
    BUGGED
     
  13. agnis16

    agnis16

    Joined:
    Aug 1, 2018
    Posts:
    3
    FIXED / SOLUTION
    Disable the animation preview button after playing an animation.
     
  14. GonzoBonDonzo

    GonzoBonDonzo

    Joined:
    Jul 29, 2022
    Posts:
    63
    I'll add my story to this "feature" as well.

    When this issue start happening to me, I actually restarted my project from scratch, because no matter what I did, what I set to change in my script, I couldn't get my float value to change anymore... I checked, doubled checked, re-wrote, searched for solutions... Why wasn't my float changing?? What the heck did I do?

    I ended up writing so much, I thought I had completely borked my script. So I restarted. I couldn't figure out where I went wrong and figured I messed up something bad. Best to restart then, learn some more in the process.

    Everything was going great again, everything was working how I wanted. And then, I was about at the point I was before, and I added an animation...

    I used the animator to set a float to a value at the beginning of the animation (and made sure to return the value back to it's original at the end of the animation think I was being smart). Whoops! My float was locked up again (to the value set at the end of the animation). I was really depressed.... but at least I finally realized what the problem was. It was using the animator to set the value.

    How can if be, that if you set a value in the animator... it's locked (for me, once that animation plays)? Even if a script properly calls to change it afterward? I can understand if you *solely* used the animator to make changes floats/ints/bools.... But if you are using scripts?
     
    ModLunar likes this.
  15. Ultroman

    Ultroman

    Joined:
    Mar 10, 2014
    Posts:
    110
    This is not intuitive at all. We really need to disable the Animator in order to change anything either of its animation clips touch? So we can't have animation clips running while changing things that aren't currently being animated by the Animator, if ANY animation clip within it touches that same thing? How is that intuitive? At least we can make it remember its state when disabled with
    animator.keepAnimatorControllerStateOnDisable = true;
    . Won't it just go back to the Animator-locked value as soon as I start the Animator again, though? That is ridiculous. It should be Animation-driven, not Animator-driven.
     
    AldeRoberge likes this.
  16. Karsten

    Karsten

    Joined:
    Apr 8, 2012
    Posts:
    189
    LateUpdate() is the wey
     
  17. GonzoBonDonzo

    GonzoBonDonzo

    Joined:
    Jul 29, 2022
    Posts:
    63
    Where does
    animator.keepAnimatorControllerStateOnDisable = true;
    go? I've tried putting it in Start and Update, but it doesn't solve the issue
     
  18. Ultroman

    Ultroman

    Joined:
    Mar 10, 2014
    Posts:
    110
    It is a bad solution to a design-time problem. Your code is executing code that changes something every LateUpdate(), something that your Animator is changing back every Update() and FixedUpdate(). It is bad design and bad for performance. If you only have few of the Animator or not a lot happens, I'm sure it's fine, but it's still bad.

    It goes in Awake() or Start(); just call it once for the Animator in question. Whether it fixes your issue, depends on what your issue is. It solves some issues, as it prevents the Animator from resetting its state when is gets disabled, so when you enable it again it'll retain its state. That doesn't really help with the original problem of these variables being locked, though, just that when you disable the Animator in order to change these locked values, you can get back to the Animator's saved state when you enable it again, instead of it having been reset.

    Semi-related: Animation Events are useless due to them being unpredictable. If the frame is skipped, the Animation Event is skipped...who designed it that way? Seriously... Any lag or speeding up of a clip, will result in skipped frames and thus skipped Animation Events.
    If anyone else is having problems with Animation Events being absolutely useless, create your own StateMachineBehaviour to gain control of your states at runtime, or get this asset that did it already in a generic way.
     
    Last edited: Aug 23, 2022
    admin_unity602, ModLunar and Grafos like this.
  19. Karsten

    Karsten

    Joined:
    Apr 8, 2012
    Posts:
    189
    somewhat I agree, turning the behaviour around , so that Animator is doing "LateUpdate" could be a solution, what do you think?
     
  20. Ultroman

    Ultroman

    Joined:
    Mar 10, 2014
    Posts:
    110
    I think I'd rather remove the animation of the variables I don't want to have locked, and instead use events (Animator Events using the asset Animator Events, NOT Animation Events which are unreliable) to trigger the changes to the variables in code. That removes the need for LateUpdate() entirely, since the variables are no longer locked, so I can change them in code as I'd like, AND the events are predictable.
     
    Last edited: Aug 23, 2022
    Mykola_Khimich likes this.
  21. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,533
    At the very least, all Animator-Locked properties should get an icon in the Inspector. This wouldn't fix the problem, but it would at least educate users with a tooltip to hint at what is going on. "Why isn't this working? Oh, what's this little icon?"
     
  22. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    349
    Completely agree.
     
    ModLunar likes this.
  23. Zanthous

    Zanthous

    Joined:
    Sep 9, 2015
    Posts:
    4
    The animation system finds a new way to upset me every time I use it. This time was this problem
     
    andreiagmu and ModLunar like this.
  24. Zanthous

    Zanthous

    Joined:
    Sep 9, 2015
    Posts:
    4
    Now the annoying part is when I am actually animating the variable, the animation doesn't overwrite the code that sets the variables manually. This is why this sucks
     
  25. SkylorBeck

    SkylorBeck

    Joined:
    Aug 29, 2020
    Posts:
    13
    I found the solution to be, as with a lot of things, using a third party fix like DoTween. Unreal that this is still the way it is.
     
  26. Finneganmac

    Finneganmac

    Joined:
    Oct 31, 2020
    Posts:
    2
    For anyone searching through this ancient thread in 2022, I just spent 2 hours trying to figure out why my script for rotating my object that was working previously was no longer working, and the solution was to Enable Apply Root Motion On the Animator Component.
     
  27. valentin56610

    valentin56610

    Joined:
    Jan 22, 2019
    Posts:
    159
    Well it's 2022 and this is STILL the same

    Jesus, oh my god this is getting really frustrating to even use Unity in the first place!

    Now I have 50 weapons to re rig because of poor thinking from Unity's devs

    Hats off to you for this mess
     
    Ultroman and literacy like this.
  28. kzkkzm

    kzkkzm

    Joined:
    Jan 6, 2023
    Posts:
    3
  29. artfabrique

    artfabrique

    Joined:
    Nov 8, 2012
    Posts:
    25
    Hey Unity guys, it's time to break the backwards compatibility and change the logic here. Projects will update the code, you will earn some money from enterprise support. C'mon it's a win-win for you.
    Also +100500 that such behavior makes it impossible to use animator for complex mobile rpg games with tens of millions of players ;) I strongly ask to reconsider approach here.
     
  30. unity_dev421

    unity_dev421

    Joined:
    Feb 22, 2022
    Posts:
    3
    +1 from here.
     
    Ultroman likes this.
  31. jf065d

    jf065d

    Joined:
    May 28, 2018
    Posts:
    23
    I just want my Camera to play an animation at the start of a round (which includes adjusting its "Size"), but then allow the player to control the camera size via player inputs: If player is pressing a button(s), the camera slowly zooms in (i.e. increases Camera size); if player releases button(s), the camera slowly zooms back out from it's current zoom size (i.e. reduces Camera Size).

    I guess I'm going to have to pick among:
    1. Turning the Animator on/off each time after start animation and then using script to adjust the camera size/zoom.
    2. Scrapping the Animator component altogether and just playing the start the animation by calling an Animation component, Or
    3. Somehow using the Animator to control zoom in/out (though I'm not sure how I'd run a zoom animation without dynamically telling the animation what it's starting size/zoom value is). :(
     
    Last edited: Jun 19, 2023
  32. AldeRoberge

    AldeRoberge

    Joined:
    Jun 23, 2017
    Posts:
    65
    Use LateUpdate instead of Update.

    Just to make this clear for everyone.

    If you find yourself in a frustrating situation where you object does not animate properly (i.e. value does not change from script), even when the Animator is not playing any clips changing that value, you must use LateUpdate to perform your changes instead of Update.

    This begs the question : Why is Unity changing the values of animated properties, even when an empty clip (that doesn't need to change the value) is playing? This is very counter intuitive, and had I not stumbled upon this thread, I would have wasted many many hours trying to figure it out.
     
    cdr9042 and spider853 like this.
  33. spider853

    spider853

    Joined:
    Feb 16, 2018
    Posts:
    42
    Bumping this thread as hitting the wall again with this stuff, I understand it might be hard for Unity team to find a solution because of transitions, but probably they can use the current value as transition start and lock them from that point if it transitions in that animated property animation
     
    cdr9042 and valentin56610 like this.
  34. valentin56610

    valentin56610

    Joined:
    Jan 22, 2019
    Posts:
    159
    Even this didn't work for me... Performing lerping in LateUpdate() didn't do anything, but as soon as I disabled the animator it was OK...
     
  35. cdr9042

    cdr9042

    Joined:
    Apr 22, 2018
    Posts:
    175
    I used Animancer Lite (no Animator) as a workaround. Having to rewrite code to move object in LateUpdate() is impossible
     
    ModLunar and valentin56610 like this.
  36. acor07

    acor07

    Joined:
    Jun 29, 2019
    Posts:
    4
    Also ran into this when disabling and then re-enabling the component that has the animator. For some reason it starts out letting me control the transform through scripting even with the animator on. However, when I need to disable and then enable the component it will lock the transform... that has to be a bug, why would enable/re-enable cause different behavior?
     
  37. Fr1k

    Fr1k

    Joined:
    Jun 29, 2017
    Posts:
    1
    After aggregation of all the answers the solution that helped me:

    void Awake()
    {
    GetComponent<Animator>().keepAnimatorStateOnDisable = true;
    }

    myObject.GetComponent<Animator>().enabled = false;
    // do something with locked properties
    myObject.GetComponent<Animator>().enabled = true;
     
    ModLunar and cdr9042 like this.
  38. Decreationist

    Decreationist

    Joined:
    Nov 15, 2016
    Posts:
    4
    2024, issue is still around.

    Unbeliveably weird design choice, something simple such as our setup (attacks have curves to drive some parameters in the editor, nothing else has combined with Animator Override Controllers) forces us to have an empty, flat curve with value 1 in EVERY animation.
     
    valentin56610 likes this.
  39. DucakaJeff

    DucakaJeff

    Joined:
    Feb 9, 2022
    Posts:
    1
    For someone still have this issue with material variable:
    Modify MaterialPropertyBlock in LateUpdate is the answer
     
  40. Fobri

    Fobri

    Joined:
    Jan 28, 2014
    Posts:
    31
    How is this still a thing? Every time I work with the animator in Unity I feel like im eating old moldy bread...
     
    valentin56610 likes this.
  41. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    341
    Wow. I thought I have seen the worst before. Now I see I haven't until this.
     
    valentin56610 likes this.
  42. Karsten

    Karsten

    Joined:
    Apr 8, 2012
    Posts:
    189
    LateUpdate() guys, thats what you looking for