Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 $$anonymous$$d 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.

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

how can I play an animation from a different gameobject? 0 Answers

Issue with using additive animation clips imported from one .FBX 0 Answers

add panel between two animation clips in animator 0 Answers

Accessing a Mecanim state through scripting, then changing the associated clip--Can it be done? 2 Answers

"model@animationclip" doesn't work as expected 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges