Search Unity

Inactive Animation is blockin transform manipulation

Discussion in 'Animation' started by Sandler, Jun 23, 2016.

  1. Sandler

    Sandler

    Joined:
    Nov 6, 2015
    Posts:
    241
    As the title says,
    i was wondering why an animation that is not playing is blocking manipulations of c# animation.
    Is this a wanted behaviour? Or am i missing something?

    thanks!
     
  2. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    196
    I'm not sure what you mean by C# animation...are you talking about manipulating translation/rotation through code and an animation appears to be keeping that from happening? There are several reasons why such a behavior would happen, so if you could describe your case in a bit more detail that would be really helpful.
     
  3. Sandler

    Sandler

    Joined:
    Nov 6, 2015
    Posts:
    241
    Yes exactily, im tweening the rotation values of an gameobject via c#.
    As i created an dance animation, im manipulation those same transforms rotations via unitys animation system.
    Now the rotation wont apply, even if the unity animation is not playing. They are stuck at 0 and cant be manipulated (not even through the editor).

    If i just remove the reference in the state machine, my c# animation is played again.
    Just wanted to know if this is a normal behaviour?
    I could wrap specific elements in a additional gameobject or create an second animator for such dance animations.

    Thanks a lot!
     
  4. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    196
    As far as I can tell this is the intended behavior. Transform rotation is going to be controlled by animation and Unity will maintain the position of the last active keyframe in a non-looping animation unless the state exits. You might be able to transition an empty state, one that doesn't have an animation clip, and manipulate the transforms while in the statemachine is in that state...however, that is just a guess since I'm away from a machine I can test on.
     
  5. Delmadan

    Delmadan

    Joined:
    Apr 8, 2014
    Posts:
    6
    I know this is an old post but I just wanted to chime in to say that I am having the same issue. I haven't found a way around this problem yet except to add a separate Animator component to the game object which contains the states that affect the transform. Then, when you want to programmatically affect a transform, you would need to disable that Animator.

    It's a crappy work around - it seems odd that it is normal behaviour for the Animator to override transform manipulation simply due to their being a state that affects that transform (even if it is never played).
     
  6. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    196
    @Delmadan You could do any changes you need to make in code in LateUpdate() rather than having to worry about disabling the Animator component. The way the animation system works, you will see the following order:
    1. Update() - any changes to any property that is animated will be lost
    2. Internal Animation System Update - This overrides those changes that were attempted in Update()
    3. LateUpdate() - This is where changes can be made to properties that were affected by the animation system
    Here is a link with all the order of stuff if you are wondering about what the actual logic flow order is. https://docs.unity3d.com/Manual/ExecutionOrder.html However, you should be good knowing that LateUpdate() is the key to changing stuff that is referenced in an animation.

    Cheers,
    TrickyHandz
     
  7. krunoslavg

    krunoslavg

    Joined:
    Sep 5, 2018
    Posts:
    3
    Hi, guys. Acutally having the same problem and only thing which works is to disable Animator. Also, your suggestion to try LateUpdate() doesn't work. Even with it, I have to first disable Animator cmponent to be able to manipulate transform of the object.
    Technically it works, but it is battle between animator and script. So, script moves transform and animation puts it back.
     
    Last edited: Jul 23, 2019
  8. Sandler

    Sandler

    Joined:
    Nov 6, 2015
    Posts:
    241
    just put the transform you want to target by c# in an additional gameobject.

    BaseTransformC# -> BaseTransformAnimator

    Not the best solution, but the easiest
     
  9. krunoslavg

    krunoslavg

    Joined:
    Sep 5, 2018
    Posts:
    3

    Hmmmm, dude, you actually have right. So parent could be animated by animator and child by script, since they must have different movement. Oh. TY SO MUCH FOR IDEA! :D
     
  10. GroovyGamer10

    GroovyGamer10

    Joined:
    Jan 31, 2024
    Posts:
    1
    thanks so much dude that worked