Search Unity

Mecanim - Play Random Animations in Idle State

Discussion in 'Developer Preview Archive' started by BigToe, Sep 25, 2012.

  1. BigToe

    BigToe

    Joined:
    Nov 1, 2010
    Posts:
    208
    One thing I like about the Sage animation editor is that I can create an animation state that has a list of animations that it will play randomly. This is good for idles if I want some variance.

    I was wondering what the best approach for changing between random idle animations in Mecanim would be? Should I create an Idle blend tree, then inside of that create the number of possible idle animations? Say I have 4 idle animations...Would I create an Integer Parameter from 1-4 and randomly update that in code to make it blend between the different idle animations?

    Or is this a case where I should be using layers or sub-state machines?

    Also, is there a way to fire an event when an animation finishes?

    Thanks!
     
  2. pierrepaul

    pierrepaul

    Unity Technologies

    Joined:
    Jun 19, 2012
    Posts:
    162
    I would do a BlendTree in the Idle state. The BlendTree would have RandomIdle (a float) as its BlendParameter, and externally I would take care of changing the RandomIdle to make the randomnes happen.



    Not at the moment. But you can always check the normalizedTime of the animation at each frame use GetAnimatorStateInfo(layerIndeX). That should do it!
     
    theANMATOR2b and rakkarage like this.
  3. ddesmond

    ddesmond

    Joined:
    Feb 9, 2010
    Posts:
    163
    Hello PierrePaul,

    How would you specify specific start/end frames with mecanim in code?
     
  4. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    Set booleans to drive transitions upon registering as true. it then transitions through a blend you have edited in the Preview window and into the animation you choose in the blend tree by whatever method. A good way to set up multiple choice based on random input is to use ints when specifying which animation and have that animation be in that position on the blend tree graph. Say you have 4 animations. You would create four Motion slots on the blend tree and set the range at 1 and 4 at either ends.. Then the motion clips should be basically soloed on each integer and you call an int to access it.

    HTH
     
    theANMATOR2b likes this.
  5. pierrepaul

    pierrepaul

    Unity Technologies

    Joined:
    Jun 19, 2012
    Posts:
    162
    You cant really change the start/stop time of clips without reimporting the animation, or setuping transtions so that the states start and end at specific time .

    pp
     
  6. ddesmond

    ddesmond

    Joined:
    Feb 9, 2010
    Posts:
    163
    Thanks ippdev for your response, that sounds like a great idea. Thanks for your input as well pierrepaul, are you able to do what said via code or only through the UI?
     
  7. pierrepaul

    pierrepaul

    Unity Technologies

    Joined:
    Jun 19, 2012
    Posts:
    162
    We wont support API control over transition in 4.0. So only in the UI.. for now :)

    pp