• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by xEnOnn · Mar 30, 2013 at 04:57 PM · animationclips

How can I play a few animation clips one after another?

How can I play a few animation clips one after another? I have clipA, clipB and clipC. In my code, I want to play these clips randomly, but one after another. So it could start from clipB first, then after clipB is done playing, go on to play clipC, then clipA and so on.

I have tried PlayQueued. But it doesn't work as I expected it to be.

Here's my usage:

 animation.PlayQueued("clipB", QueueMode.CompleteOthers); 
 animation.PlayQueued("clipA", QueueMode.CompleteOthers); 
 animation.PlayQueued("clipC", QueueMode.CompleteOthers); 
 animation.Play();

But this doesn't play the clips at all.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dorpeleg · Mar 30, 2013 at 05:04 PM 0
Share

PlayQueued should work perfectly.

I used it myself to do the same.

You mind showing the code? maybe we can see what's wrong.

avatar image xEnOnn · Mar 30, 2013 at 05:07 PM 0
Share

I have edited my question with my code.

avatar image RnD123 · Aug 14, 2017 at 05:50 PM 0
Share

This is quite old but for people who may stumble upon this in the future, be sure that the animation is not set to loop, otherwise it won't play queued animations.

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by fafase · Mar 30, 2013 at 06:38 PM

Here is a custom version:

 IEnumerator QueueAnim(params AnimationClip[] anim){
    int index = 0;
    animation.clip = anim[index];
    while(index<anim.Length){
       animation.Play;
       yield return new WaitForSeconds(anim[index].length);
       index++;
       animation.clip = anim[index];
    }
 }


Then you call it as such:

 void Update(){
   if(animQueue){
     StartCoroutine(QueueAnim(animation["Anim1"],animation["Anim2"]));
     animQueue = false;
   }
 }


I am doing this on top of my head with no Unity to try so there could be issues... You can pass as many animation clips as you wish since it uses params. But again, it could be all wrong...

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by dorpeleg · Mar 30, 2013 at 06:14 PM

Here is a function I made that works for me:

 void RandomizeAnimation (GameObject crowd) {
         int RndAnim = UnityEngine.Random.Range (0, Animations.Length);
         int RndSpeed = UnityEngine.Random.Range (1, 100);
         float RndFade = UnityEngine.Random.Range (0.1f, 1f);
         crowd.animation.CrossFadeQueued("anim"+RndAnim, RndFade, QueueMode.CompleteOthers);
         crowd.animation["anim"+RndAnim].speed = RndSpeed;
         
     }

The gameobject have many animations, all animations are named anim1, anim2, anim3 etc.

I hope you can understand it, if you have any question just ask :)

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image xEnOnn · Mar 30, 2013 at 06:24 PM 0
Share

Thanks! Is this function run in the Update or Start function? It's weird because when I use this, the animation doesn't run at all. I had it inside my Update function though. And those animations that I have are not made in Unity but animations that come with an fbx model. Would this matter?

avatar image dorpeleg · Mar 30, 2013 at 06:41 PM 0
Share

Yes, it should be called from the Update() function.

$$anonymous$$ake sure you have the Animation Component on your gameobject and that all of your animation are listed in that component.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can I make animations snap to a frame? 2 Answers

Upgrade to Unity 5, animation problems 1 Answer

A simple animation clip scripting control example... DOES NOT EXIST! - loosing clumps of hair on this one 1 Answer

My machine gun code steels my clips 4 Answers

What 2d animation clips can I import into Unity? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges