Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
3
Question by siddharth3322 · Apr 10, 2016 at 03:56 PM · animationunity 5animator controlleranimationclip

Play animation single time and move back to default animation

As per my title suggest I want to play my other animation single time and then move back to default animation. Here I give my actual example so that you will become more clear.

alt text

Here in above image, "BabyGrayMainAnim" is my default animation and "BabyGraySwatAnim" is my other animation that I want to play. In this, "BabyGraySwatAnim" I want to play single then my default animation play as normal. At present I have set bool condition for this and written following code:

     public void HitFlyingBirds ()
     {
         if (myAnimator.GetCurrentAnimatorStateInfo (0).IsName ("BabyGraySwatAnim"))
             return;
 
         myAnimator.SetBool ("IsSwat", true);
         StartCoroutine (RunBabyGrayMainAnimation ());
     }
 
     IEnumerator RunBabyGrayMainAnimation ()
     {
         yield return new WaitForSeconds (1f);
         myAnimator.SetBool ("IsSwat", false);
     }

But using Enumerator for this purpose is not that much good as per my understanding. I want some better way to implement same thing. If you want more information then ask me for it. Please give some suggestion for this.

screen-shot-2016-04-10-at-91711-pm.png (16.1 kB)
Comment
Add comment · Show 6
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 arain55 · Apr 10, 2016 at 05:42 PM 0
Share

what do you mean by a single time? try turning off the loop in the animation

avatar image siddharth3322 arain55 · Apr 11, 2016 at 01:42 PM 0
Share

@arain55, I know how to run animation single time but my question is I want to start playing my default animation again.

At present what is happening!! $$anonymous$$y swat animation place once and then stop. Not started default animation again.

avatar image siddharth3322 siddharth3322 · Apr 11, 2016 at 01:44 PM 0
Share

I have written code to run my default animation that I don't want.

avatar image KdRWaylander · Apr 11, 2016 at 01:50 PM 0
Share

Not used Animator for a while but let me try something: can't you set the SWAT→$$anonymous$$AIN transition to a bool that would always be true ?

avatar image siddharth3322 KdRWaylander · Apr 11, 2016 at 01:54 PM 0
Share

@$$anonymous$$dWaylander, Basically my main(default) animation is always playing because it is general player movement animation. Swat animation is just hitting animation so at button press event I want to play it just single time then move back to original one (main animation). Something like this kind of animation playing I want.

I have set bool to play set animation but again set false to bool to play main animation again. That I don't want because it is ugly thing I am doing.

avatar image siddharth3322 KdRWaylander · Apr 11, 2016 at 01:54 PM 0
Share

I hope that some better way definitely exist.

3 Replies

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

Answer by ben-rasooli · Dec 05, 2017 at 09:45 AM

Use myAnimator.SetTrigger ("swat"); And of course you need to have that parameter "swat" set in your Animator tab.

When you wanna play an animation only once and then transition to previous state, you need to use trigger parameter, not bool. And then on the triggered animation, you set what should happen when it's finished. For your case, you can simply leave the transition condition empty and it'll go back to previous state when the animation is finished.

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
0

Answer by KaushikRahul · Apr 11, 2016 at 02:37 PM

Okey just to tell you that is not the Ugly way to do it. It is how its done for the most part if we don't want to use a lot of parameters to control out animator.

if you still don't want to do it, the other way around is make separate parameters for separate animations then from the "Any State" state make a transition to your animation and set the parameter to true of what animation you want to run.

But do make sure, every time you want to play any other animation (the parameter you are going to create for your main animation as mentioned above), you have to set it false or the any state will keep calling your main animation and won't let you play other animations.

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
0

Answer by unity_bpbhLVPIKVrCcQ · Aug 31, 2021 at 10:17 PM

  1. Create trigger parameter instead of bool

  2. Set on "BabyGraySwatAnim -> BabyGrayMainAnim" transition Has Exit Time = true

  3. Remove any conditions on "BabyGraySwatAnim -> BabyGrayMainAnim" transition

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

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

98 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Animation created via script does not play 1 Answer

Animator Override Controller changed at runtime doesn't always play the animations correctly 1 Answer

Unity 5 Controlling Animation with UI Button 0 Answers

How do I activate an animation when a gameobject enter the Collider of the other animated object 2 Answers

Why does my transition freeze the second animation on it's first frame? 1 Answer


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