Search Issue Tracker

By Design

Votes

0

Found in

4.6.0b16

Issue ID

627156

Regression

No

If animation is played before activating inactive game object it will never play animations when game object will be active

Animation

-

To reproduce:
1. Open attached project
2. Open AnimationBugTest scene
3. Press play
4. Press Set Inactive
5. Press Play Idle
6. Press Set Active
7. Press Play Break
8. If a game object with a legacy animation component is set inactive before playing an animation and an animation play happens before the object becomes active it will never play any animations.

Workaround:
Enable Play Automatically on animation component.
Play an animation before inactivating the game object.

Comments (10)

  1. nihao123456ftw

    May 26, 2019 10:20

    Fucking great. Entire backbone of my application logic is to set gameobjects with models to inactive while they are not in use. What a horrible design.

  2. Menion-Leah

    Dec 12, 2018 18:11

    "By design".. unbelievable.
    Lost hours trying to figure out what was happening.
    No mentions on the docs, no hints, no exception/logs to help.

    Terrible way to handle a design flaw.

  3. DBrakeley

    Jun 22, 2015 14:49

    I just found some code in our code base that also works around this. I ended up here when googling the issue to see if it was fixed. "By design" without any explanation isn't really helpful to people who see this.

    Here's the overview of what our code does: after loading a resource and parenting it into the scene, we save off the current activeSelf state of the root object, SetActive(true), look for an Animation component, if found, touch each AnimationState, recursively call this function on each child, and then finally restore the initial activeSelf state. It is not pretty.

  4. DBrakeley

    Jun 18, 2015 21:00

    I just found some code in our code base that also works around this. I ended up here when googling the issue to see if it was fixed. "By design" without any explanation isn't really helpful to people who see this.

    Here's the overview of what our code does: after loading a resource and parenting it into the scene, we save off the current activeSelf state of the root object, SetActive(true), look for an Animation component, if found, touch each AnimationState, recursively call this function on each child, and then finally restore the initial activeSelf state. It is not pretty.

  5. RKSandswept

    Sep 18, 2014 06:04

    nswers.unity3d.com/questions/785821/gun-reloading-animation-fails-to-find-state.html

  6. RKSandswept

    Sep 18, 2014 06:02

    There is more to this saga.....

    The bug is still there. But I found 2 postings that say something like...
    "Click on your animation file in the Unity Project Pane tab, and on the side the Inspector should be there, right click on the Inspector tab and select Debug. Once you're there, simply change the animation type from 2 to 1."

  7. RKSandswept

    Sep 18, 2014 05:03

    Better solution....

    public static void CrossFade(Animator a, string stateName, float dur, int layer, float normalizedTime)
    {
    if(a && a.enabled && a.gameObject.activeSelf)
    {
    a.CrossFade(stateName, dur, layer, normalizedTime);
    }
    }

  8. RKSandswept

    Sep 18, 2014 04:44

    Also if it is 'by design' then why is there no note in the docs, nor do the doc examples show a if(...) check?

  9. RKSandswept

    Sep 18, 2014 04:42

    if(animator.enabled)
    {
    animator.CrossFade( "hunting_crossbow_idle", 0.1f, -1, 0.0f );
    }

    or

    if(gameObject.activeSelf)
    {
    animator.CrossFade( "hunting_crossbow_idle", 0.1f, -1, 0.0f );
    }

  10. RKSandswept

    Sep 18, 2014 04:37

    On our project we have our own LOD switching (not Unity's LOD built-in)
    We hit this bug and it drove us crazy for months.
    I now have checking code to only set an animation (CrossFade) if the Animator is enabled.

    This is by-design?????????

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.