Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Entry state always uses default transition and ignores other conditional transitions (Bug?)

Discussion in 'Animation' started by achimmihca, Mar 27, 2016.

  1. achimmihca

    achimmihca

    Joined:
    Feb 13, 2016
    Posts:
    16
    Hi,

    for a test I created an empty GameObject and Animator. The Animator has two states, Open and Closed. Further it has a property Open.
    Now, if the Open property is true the Entry state should transition to the Open state. If the Open property is false the Entry state should transition to the Closed state.

    Problem is that the Entry state always transitions to the default state---even if other transitions have triggers that evaluate to true. So the transition to the Closed state is taken although the Open property is true.

    Is this a bug or is the default transition of the Entry state the first that is tested and thus is always taken? This would make other transitions on the Entry node useless.
     

    Attached Files:

  2. pratikhr-hirpara

    pratikhr-hirpara

    Joined:
    Jan 9, 2014
    Posts:
    2
    Hey I am also facing the same problem and I got the solution but solution is like hack. I made one empty state that have default transition from entry state and than i have triggered two more conditional transition from empty state. Its working for me. IT seems hack so I am recommending to find out proper solution.
     
  3. pratikhr-hirpara

    pratikhr-hirpara

    Joined:
    Jan 9, 2014
    Posts:
    2
    Here is my solution. Here in "new state" there is no animation clip. Its behaving like empty conditional node.
     

    Attached Files:

  4. Homer-Johnston

    Homer-Johnston

    Joined:
    Nov 26, 2012
    Posts:
    46
    Just want to bump that I'm having this problem too. If you transition into a sub-state-machine from another running state, the sub-state-machine will properly use the Default Transition only after evaluating all other transitions. If the layer reaches an Exit state, the layer Entry node does not evaluate any of its transitions.

    Unity needs to either fix this so the Layer Entry node evaluates other transition conditions first, or prevent users from adding transition nodes from the Layer Entry node.

    I'm a bit out of date on 5.3.2f1 but this bug has been around for at least 1.5 yrs... http://forum.unity3d.com/threads/su...ecedence-over-the-other-possibilities.294354/

    Is there a bug report for this anywhere or can anyone confirm that it is fixed in the newest Unity version? I would hope this gets fixed because this makes state machines *way* more difficult to build. Instead of the nice example from the documentation (see below) you have to create unique transitions from every single state to every other state to get the right behaviour.

    Using the "empty node" hack does not work because the gameobject will animate that null-animation for one frame which looks terrible, unless it is an Additive layer maybe.



    http://docs.unity3d.com/Manual/StateMachineTransitions.html
     
    Damjan-Mozetic and dreasgrech like this.
  5. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    267
    We don't have any outstanding bugs filed about this, which either means no-one filed a bug, or this has been fixed.

    If this is still happening in 5.3.5 (and later) or 5.4.x please file a bug
     
  6. DirtyHippy

    DirtyHippy

    Joined:
    Jul 17, 2012
    Posts:
    195
    Has anyone tried this on 5.3.5+ as the UT rep suggests? I've had this issue forever (am currently on 5.3.3 where it still exists). I don't feel like upgrading right now to find out if it works in 5.3.6 as it is not a critical issue.
     
  7. Maxpeinas

    Maxpeinas

    Joined:
    Feb 19, 2014
    Posts:
    16
    I always add idle animation on entering state machine and then conditions for transition, works fine for me.
     
  8. dreasgrech

    dreasgrech

    Joined:
    Feb 9, 2013
    Posts:
    193
    Still the same broken behavior on Unity 5.5.3p1.
     
  9. DirtyHippy

    DirtyHippy

    Joined:
    Jul 17, 2012
    Posts:
    195
    I solved my particular problem by transitioning nodes to themselves to prevent the default transition from ever being evaluated.
     
  10. codegasm

    codegasm

    Joined:
    May 3, 2015
    Posts:
    10
    Coming directly from the entry state into a sub-state machine doesn't call the OnStateMachineEnter method, only when the transition comes from another state in the top level machine. That's why adding an empty state fixes the problem. The downside of that as mentioned is the time spent in that empty state.

    I found another workaround for the specific situation when you have one sub-state machine with a StateMachineBehaviour attached that controls which clip to play on entry in the sub-state:

    1: Build the sub-state machine with entry conditions and let each state transition to exit when done.
    2: Make the sub-state machine the default state on the top level machine.
    3: Instead of transitioning from the sub-state machine to exit on the top level you transition back to itself.

    Step 3 is the key here, I wasn't aware that one could even do that. But the result is that from the second time around the transition to the sub-state machine is technically from another state (itself) and as such it calls the OnStateMachineEnter method on the StateMachineBehaviour.

    One downside I see is that it will always start with a specific state but in my case that isn't a big issue. Another is that I'm guessing that the OnStateMachineExit is never called.
     
  11. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    157
    Still happening in unity 5.6.4f1

    This picture won't work, as far as I know



    But if you go Entry > default > multiple transitions > exit and turn off "has exit time" and change transition duration to 0, the transition goes to the correct state instantly.
     
  12. Onsterion

    Onsterion

    Joined:
    Feb 21, 2014
    Posts:
    206
    Same problem here and we are in......... 2018 o_O



    Any solution?
     
    Last edited: Mar 20, 2018
    nepoez likes this.
  13. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    267
    The orange State in your state machine is the default state for your layer.
    It will always be the default state getting played when you start your state machine, no matter what.
    If you want to force another state to play, you can call
    Code (CSharp):
    1. animator.Play(<YourState>);
    2. animator.Update(0); //force transition
    before the animator is evaluated. You can do it in Start, or you can do it in Update, or you can do it in FixedUpdate if your animator is in Animate Physics mode.

    You can even technically call this in a StateMachineBehaviour.
     
  14. Onsterion

    Onsterion

    Joined:
    Feb 21, 2014
    Posts:
    206
    I don't want to force nothing, i want to get the a correctly process of parameters in the "Entry" state.

    If enter from State (X or Any State) to "Entry" the transition with parameters is procesed but if the "Entry" is entered by "Exit" the transitions with parameters are voided.
     
  15. Sarudan

    Sarudan

    Joined:
    May 21, 2011
    Posts:
    47
    I'm running into this exact same issue in Unity 2018.1.5 after doing some state machine refactoring. Unity, what is going on here? Why allow other transitions from the Entry condition other than the default if they don't work? This is horribly flawed - I'm trying to set up an idle state with different sub-states (normal, in-combat, etc.), and it's proving to be very painful.
     
    Romello, Damjan-Mozetic and nepoez like this.
  16. Samhayne

    Samhayne

    Joined:
    Jun 15, 2009
    Posts:
    15
    Thanks for pointing this out.
    That bit of information helped ME to come up with a nice workaround for my problem.
    (Play random anims from the "Any State" without having to sacrifice blending => Just do the random switch with several contitional transitions from the "Entry" state of a sub-state-machine using randomly generated indices as conditions which are generated in the state machine behaviour on the sub-state-machine root node)
     
  17. Liam-Lam

    Liam-Lam

    Joined:
    Jan 31, 2013
    Posts:
    1
    2018 and this problem still exist. I found a really simple solution for this. Just DO NOT make your sub-state machine be default one. Create an empty state and set it as default. Thats all.
     
  18. mbbmbbmm

    mbbmbbmm

    Joined:
    Dec 28, 2013
    Posts:
    58
    Wow, it's pretty crazy... I now have an idle state in my base layer that immediately transitions to my idle sub-state machine. Now everything seems to work, entry conditions are evaluated properly etc. Before nothing was working at all. Unfortunate that this not documented, this thread was not easy to find...
     
  19. nepoez

    nepoez

    Joined:
    Sep 11, 2011
    Posts:
    275
    This works to make it not get into an error-nous state or even infinite loop, but it make my animation transitions aweful. Anytime a animation that comes from ANYSTATE finishes, it will go back to run that default animation before the actual animation it should run.. that's real bad and ugly. I Can't believe this is still a bug after years!!!
     
    Damjan-Mozetic likes this.
  20. nepoez

    nepoez

    Joined:
    Sep 11, 2011
    Posts:
    275
  21. Damjan-Mozetic

    Damjan-Mozetic

    Joined:
    Aug 15, 2013
    Posts:
    27
    I also have a big issue with this implementation, since I need the default state not to execute, but instead have the state chosen from a parameter. An empty first state also doesn't cut it, since it makes the animation glitch for one frame. I have asked some of my followers on twitter to vote on the issue, so hopefully it gets noticed soon and solved.
     
  22. evand

    evand

    Joined:
    May 22, 2013
    Posts:
    14
    How is this still a thing? I have to constantly add blank states to fix the animator or just do a TON of manual connections. This is a VERY common problem if you have multiple sub states and try to exit that state.

    If I have a "walking" substate for a 2D sprite and want to be able to transition to a "WalkingBare" or "WalkingShield", I need to be able to transition from Idle -> Walking and then be able to determine if the shield is equipped, then from WalkingBare or WalkingShield need to check if I'm walking and if a shield is equipped to see where I go in the Idle state.

    End result?

    An Entry node with 4 or 5 transitions... all of them ignored for whatever I set as default. This is bonkers -- why would it not just evaluate the transitions each time?