Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Mecanim "Any State"

Discussion in 'Developer Preview Archive' started by PeterB, Aug 24, 2012.

  1. PeterB

    PeterB

    Joined:
    Nov 3, 2010
    Posts:
    366
    Mecanim's "Any State" state seems to be ideal for implementing things like death sequences, which can start from anywhere.

    However, tying the transition to the state of a boolean (or a specific integer or float value, etc) causes the same state transition to be triggered over and over again, and thus the animation restarts repeatedly as long as the boolean has the same value.

    Is there a way of preventing retriggering subsequent transitions to the same state? Or is the [simplistic] intended usage pattern simply to quickly revert the boolean to its original value? If so, how quickly? In the same or next frame?
     
    Last edited: Aug 24, 2012
  2. pierrepaul

    pierrepaul

    Unity Technologies

    Joined:
    Jun 19, 2012
    Posts:
    162
    We are currently asking ourselves if we should prevent Any State transitions to be re-entrant... So you think it be enforced ?

    Until then, what you can do, is set back the boolean to false when you start transitionning to the Death state...

    You can do something like this :

    AnimatorStateInfo nextState = animator.GetNextAnimatorStateInfo(0) ; // get next state on layer 0

    if( nextState != null nextState.name == "Base Layer.DeathState")
    {
    animator.SetBool("DeahtBoolean", false);
    }

    pp
     
  3. PeterB

    PeterB

    Joined:
    Nov 3, 2010
    Posts:
    366
    Thanks for the reply, it's as I thought, then.

    I wouldn't prevent re-entrant state transitions globally. It would be very useful with a checkbox to do so locally, however.

    The above code fragment of course works very nicely, but it involves global monitoring of states, which distributes logic while still maintaining coupling. Would a simple

    suffice? Or do we need to do

    to create an animation event?

    Another thing that would be very useful is ping states, i.e. states that after completion always transition back to the previous state. This tends to simplify logic a great deal in many situations.
     
    Last edited: Aug 24, 2012
  4. pierrepaul

    pierrepaul

    Unity Technologies

    Joined:
    Jun 19, 2012
    Posts:
    162
    Neither of them would work. We would eventually like to have Delegates per State that would allow to add State specific code ( animator.SetBool("Dead", false)) but for now you have to do this manually.

    Ie :

     
  5. monsterBlues

    monsterBlues

    Joined:
    Aug 25, 2012
    Posts:
    1
    I've bumped into this issue as well. While having an option to be re-entrant would be great, an alternative solution could be found.

    Other node based animation systems I've used had a Request feature. Instead of using a bool, you could send "request" for an action. If the request is not present in any of the transition, no transition occur.

    Here's a screen of how I imagine it working.

     
    Last edited: Oct 26, 2012
    arielfel and Vince_H like this.