Search Unity

Mecanim Any State

Discussion in 'Editor & General Support' started by sirival, Nov 15, 2012.

  1. sirival

    sirival

    Joined:
    Sep 14, 2011
    Posts:
    146
    I want my character to go to the Move state whenever Speed is larger than 0, from any state. Setting a transition from Any State to the Move State with the Speed > 0 condition, makes the Move animation restart again and again.

    Can I fix this somehow from a script?
     
  2. pierrepaul

    pierrepaul

    Unity Technologies

    Joined:
    Jun 19, 2012
    Posts:
    162
    Hi.

    What happens is that you tell the system that in "Any state" that you are in, when Speed > x, transition to Move. So even when you are in Move, the transition is called !

    A way to prevent this, would be to add a bool Parameter called InMove and add the condition "InMove is false" to your AnyState Transition. You set the bool to true when you enter the InMove state.

    We have internally discussed to prevent AnyState transition re-entering the same state but decided to allow it, since it can be usefull in some instance!

    cheers.
     
  3. sirival

    sirival

    Joined:
    Sep 14, 2011
    Posts:
    146
    Hi thanks for responding. Could you give an example for when re-entering the same state again and again would be useful?

    I think it would be a lot more useful if this behavior was not the default but rather an option perhaps on the transition from Any State
     
  4. pierrepaul

    pierrepaul

    Unity Technologies

    Joined:
    Jun 19, 2012
    Posts:
    162
    Cant remember precisely why, but some team wanted to be able to re-enter the same state again.. which to think about it, is kinda odd..

    So we changed the code base on our side, and made it impossible to re-enter the same state from an AnyState transitions..

    You will have it on a future release !

    until then us what I suggested above :)
     
  5. sirival

    sirival

    Joined:
    Sep 14, 2011
    Posts:
    146
  6. JamieFristrom

    JamieFristrom

    Joined:
    Nov 2, 2012
    Posts:
    20
  7. pierrepaul

    pierrepaul

    Unity Technologies

    Joined:
    Jun 19, 2012
    Posts:
    162
    Hi Jamie.

    I would also suggest using sub-stateMachines. We made numerous workflow fixes in the next version, that will make it super easy to drop states in and out of stateMachines. Should make the graph less spagethi-like!
     
  8. pierrepaul

    pierrepaul

    Unity Technologies

    Joined:
    Jun 19, 2012
    Posts:
    162
    So guys, finally we have users that already rely on AnyState to transition states to self.

    So the fix won't be in 4.1. We started designing a system when we could reset some values to default when some transitions are taken. It won't be in 4.1 however.

    Unitl then, I would simply suggest that you give a name to your transition, and then in code do something like :

    if(animator.IsInTransition(0) animator.GetAnimatorTransitionInfo(0).IsUserName.("NameOfTransition"))
    animator.SetFloat("SomeValue", resetValue);

    hope this helps.

    cheers.
     
  9. MrGru

    MrGru

    Joined:
    Apr 29, 2013
    Posts:
    2
    Only one time it runs right, when i set bool Parameter "inMove" to true, but I can't get when it's transition "Any State" to set inMove to false :(.
    Thank you.
     
  10. hirok

    hirok

    Joined:
    Nov 2, 2013
    Posts:
    7
  11. pierrepaul

    pierrepaul

    Unity Technologies

    Joined:
    Jun 19, 2012
    Posts:
    162
    Hi

    Since 4.3 you have Parameters of type Trigger which are automatically reset to false when the transition starts.

    pp
     
  12. PeterBK

    PeterBK

    Joined:
    Jul 4, 2013
    Posts:
    1
    While the trigger parameters clear up the vast majority of the issues, I still feel that the system needs to change so states cannot transition into themselves. It's a very strange 'feature', and I have to work around it far more often than I get to take advantage of it.

    From the sound of it, you understand that it behaves in a strange way and would like to change it, but are worried that changing it now will corrupt any projects that rely on it. What if you made it an option on every state (should the state be reentrant or not) that defaults to false on newly created states, but is set to true on all pre-existing states when the project is converted?
     
  13. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    As it happens, Unity 4.5 shipped today and (I believe) contains exactly such an option on all transitions from the Any State :)
     
  14. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    And there was much rejoicing!