Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Current playing animation

Discussion in 'Scripting' started by devel, Apr 2, 2009.

  1. devel

    devel

    Joined:
    Mar 11, 2009
    Posts:
    140
    How can I get the name of the current playing animation?
     
  2. Charles Gill

    Charles Gill

    Joined:
    Aug 1, 2008
    Posts:
    142
    There isn't (as far as I know) a way to ask "Which animation is playing", in part because the question doesn't always make sense. For instance, it's common to blend multiple animation clips playing on different layers with different blend weights.

    You can, however, ask .IsPlaying() on a particular animation state to find out if a particular animation is playing or not.

    Charles
     
  3. devel

    devel

    Joined:
    Mar 11, 2009
    Posts:
    140
    And is there a possibilty to get informed that the current animation has changed..??
     
  4. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    I don't understand the question. Changed how? And as Charles said, there isn't a "current animation" in the first place. Perhaps it will be more clear if you try to tell what it is you want to do?

    Rune
     
  5. devel

    devel

    Joined:
    Mar 11, 2009
    Posts:
    140
    Ok, I will explain.

    There is an avatar A that performs several actions (animation sequence).
    A second avatar B has to react accordingly (having the right 'answer' animation).

    --> B should be informed about animation changes of A and look for the right answer

    In some way the animations need to be synchronized (B has to be able to react on A's animation after a delay of x seconds). For some other animations it is desired that A and B use the exact same animation frame index (with both Avatar animations having the same length in this case, i.ex. dancing).

    --> I need to be able to get information about the animation timing (current index within the animation, or sth like that) to control the time at which B's animation should start playing.

    Thanks.
     
  6. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    I think in this case you are better off just sending a message to (or calling a method on) B at the same time as you start the animation on A. Letting B continuously listen to animation changes on A is both more inefficient and less elegant code.

    See above.

    If you want to explicitly synchronize two animations, you can query the time of one and set the time of the other to be the same.

    Code (csharp):
    1. animation["dancingB"].time = characterA.animation["dancingA"].time;
    You can see all the AnimationState variables here:
    http://unity3d.com/support/documentation/ScriptReference/AnimationState.html

    Rune
     
  7. devel

    devel

    Joined:
    Mar 11, 2009
    Posts:
    140
    Many thanks!
     
  8. alok-kr-029

    alok-kr-029

    Joined:
    Jan 10, 2013
    Posts:
    22
    print (this.transform.parent.gameObject.animation.clip.name);
     
  9. U7Games

    U7Games

    Joined:
    May 21, 2011
    Posts:
    943