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
5
Question by Abhiroop-Tandon · Jul 05, 2016 at 02:50 PM · animationanimatortriggersanimationclip

Animation Trigger playing twice

Hello Everyone,

i can see that this question has been asked a lot but i tried them and it didn't work. I am using Unity 5.3.5. I have a trigger in my animator Attack1Trigger which should trigger my attack1 animation. I set the trigger to true using GetKeyDown(KeyCode.Space), i also tried GetKey() to be sure as well. The animations are triggered twice for some weird reason that i can't figure it out. And similarly my other animations (attack2,3 and 4) also play twice. I am able to stop that by checking the "Can transition to self" box but that is not the effect i want because then i can keep pressing the key and it will never complete the animation. Could anyone please tell me any possible solution to this problem??

Comment
Add comment · Show 4
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 YellowUromastyx · Jul 05, 2016 at 09:22 PM 0
Share

Are these animations legacy?

avatar image Abhiroop-Tandon YellowUromastyx · Jul 06, 2016 at 10:41 AM 0
Share

Thanks for the response. I dont know how to check the legacy thing. They are character animations that came with the character pack. Please find the images of how it looks

alt text

capture.png (8.6 kB)
capture2.png (23.6 kB)
avatar image YellowUromastyx Abhiroop-Tandon · Jul 06, 2016 at 01:15 PM 0
Share

Is this pack an Official unity asset? or did you get this from the asset store.

Show more comments

8 Replies

· Add your reply
  • Sort: 
avatar image
21

Answer by SteenPetersen · Apr 21, 2017 at 11:10 PM

@Abhiroop-Tandon If im not mistaken what you've done is make a very short animation clip. and as you ask it to start with a trigger you have left the "transition duration" on it in your animator from the "any state" to the desired animation.

try setting the transition duration to 0 on the line leading to your animation and see if that works.

with short animations it gives itself time to play it twice.

hope this helps someone, tis at least how I fixed this issue.

Comment
Add comment · Show 4 · 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 Rosh7X · Jun 22, 2018 at 11:33 PM 1
Share

I come back to this answer whenever this happens because I forget how to fix it every time. This is what fixes double animation every time. Thanks @SteenPetersen Even though this is very late

avatar image SteenPetersen Rosh7X · Jun 23, 2018 at 02:14 PM 0
Share

Anytime :)

avatar image DiegoWw · Jun 26, 2019 at 12:55 AM 1
Share

Logged in just to upvote this :) So simple solution but such annoying behaviour. Unity should give transitions priority, so that if an animation has no exit condition and therefore needs to go to the next state, it shouldn't be allowed to play twice, and just abort whatever transition it is in.

avatar image GameDevMark · Mar 27, 2021 at 05:10 PM 0
Share

Thank you for your answer! Worked out for me!

avatar image
5

Answer by onur84 · Sep 18, 2019 at 01:50 AM

I encountered the same problem. I solved this issue with just a line of code.

Just put that code into your triggering state's behaviour's OnStateEnter :

 //TriggerName: Put your own trigger's name here
 animator.ResetTrigger("TriggerName"); 

OR instead put the same line into triggered state's OnStateExit part.

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 dylanupde · Feb 01, 2020 at 01:35 AM 0
Share

This was the solution for me! I didn't realize triggers would stay active for so long. Thanks!

avatar image FoxAdventures · Jan 23, 2021 at 12:23 AM 0
Share

Thank you!! It's almost 3:30 am here and I've been losing my $$anonymous$$d over this for the past 30 $$anonymous$$utes. Now I can finally go to sleep lol

avatar image
1

Answer by GameDevSA · May 08, 2017 at 08:00 AM

I think most likely you are accidentally triggering the animation twice. A useful test would be to put in a debug message to confirm.

  if (Input.GetKeyDown(KeyCode.Space))
             {
                 print("Playing Attack Animation");                    
                 anim.SetTrigger("Attack");
             }

You could also try adding in a second condition to be sure, by only setting the trigger if the right animation is playing. For example, if you want to trigger an attack animation from an idle state, make sure the trigger is only set to true if the animation is currently in Idle state.

  if(other.gameObject.tag == "Player" && anim.GetCurrentAnimatorStateInfo(0).IsName("Idle"))
         {
            print("Attacking hero");
            anim.SetTrigger("Attack");           
         }

Also you might want to double check the actual transition itself. For the transition into, I had 'Exit Time' off, because I wanted it to happen immediately, but left transition duration at 0.1 under Settings. If the settings aren't correct in the actual Animator itself it may accidentally cause looping. To be safe, I reset mine, and then just turned off Exit Time, and that fixed it. Because I was originally getting weird errors even when my script looked like it should have worked, but someone else set the transition up. So I reset it and did the above, and it worked perfectly.

Hope that helps anyone else having this issue. I had to wrack my head around it for a bit.

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 nelston · Jun 28, 2017 at 03:00 AM 0
Share

Thank you very much.

avatar image THE_AMAZING_PRO_CODER · May 27, 2021 at 10:11 PM 0
Share

It worked, Huge help!

avatar image
0

Answer by YellowUromastyx · Jul 08, 2016 at 09:57 AM

@Abhiroop Tandom

(Note i am not a professional with animations but i have worked with them) This could be caused be a few reasons)

1: The animation is being called twice. This could be because the script that calls this animation is attached to more then 1 object, or the script itself calls the animation more then once. Try fixing this by putting a Debug.Log("Animation called"); where you are calling the animation from.

2: The animation could (By accident) loop the animation 2 times, its impossible to tell because they are made in an animating software outside of unity.

if these don't work try setting the animation to Legacy, you can do this by selecting the animation, then look for the icon in the inspector, in the top left there should be a small triangle pointing down with 4 horizontal lines to the right of it. When you click this a list should appear from the bottom of the icon, at the very top of the list should be an option titled "Normal" and it should have a check mark next to it. You need to select "Debug". when you open the Debug version of the animation there will be a lot of options, just 3 options down there should be a check box and to the left of it it should say "Legacy", select this check box then go back to Normal by following the same steps you did to get to Debug. Legacy animation can NOT be called in the animator and must be called via script. I am using C# in this example but i can convert it to Java as well. Use this script to call the animation.

 using UnityEngine;
 using System.Collections;
 
 public class CallAnimation : MonoBehaviour {
 
     public Animation attackAnimation;
     // We will set this to the desired animation in the inspector
     void Update () {
 
 
         // you can use Input.GetKeyDown also
         if (Input.GetButtonDown ("Fire1")) {
             attackAnimation.Play ();
             Debug.Log ("Attack animation has played!");
         }
     }
 }

Put this script on an object, you will see a bar that has "None (Animation)" written on it. Click the dot to the right of the bar and select the animation that you set to legacy. (If the animation is NOT legacy it will not work) make sure a game object has the Animation Component attached to it and the Animation is assigned in the Animation Component. when you play your game and hit the Left Mouse Button the animation should trigger and text should appear in the console saying "Attack animation played!". If you receive an error saying "UnassignedReferenceException: The variable attackAnimation of CallAnimation has not been assigned. You probably need to assign the attackAnimation variable of the CallAnimation script in the inspector." then that means you did NOT assign the animation to the script, you must do this via the inspector. I hope this helps and i am very sorry if it does not.

This is a image of the icon with he upside down triangle with the 4 lines. (its a bit blurry) alt text


boop3.jpg (36.0 kB)
Comment
Add comment · Show 5 · 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 YellowUromastyx · Jul 08, 2016 at 10:57 AM 0
Share

I hope this helps

avatar image Abhiroop-Tandon · Jul 08, 2016 at 11:03 AM 0
Share

@YellowUromastyx I really appreciate your elaborate answer. I followed as you said and for some reason i cannot make the animation legacy alt text

Then i tried the debug thing and figured out that my debug statement executes only once but the animation is played twice. Would you know how to fix that?? The thing to note here is if in my animator i select those arrows and check "Can transition to self" it then plays the animation only once. But then obviously i can keep pressing the key and it will restart the animation before its finished and will never finish the animation(which is not the desired effect).

Could you please help ?

capture.png (15.0 kB)
avatar image YellowUromastyx Abhiroop-Tandon · Jul 08, 2016 at 10:34 PM 0
Share

I don't know how to help with this, this is likely a problem with the animation itself. Sorry for the inconvenience.

avatar image Abhiroop-Tandon YellowUromastyx · Jul 11, 2016 at 08:53 AM 0
Share

No problem @YellowUromastyx. Thanks for your time though :) !!

avatar image hcs · Sep 03, 2018 at 05:39 AM 1
Share

Thanks, YellowUromastyx, your first suggestion was very helpful. I was having the same problem and added the Debug.Log() as you suggested to find that, even though the script wasn't calling the animation twice, it was being called twice. Turned out I was holding space down for a fraction of a second and my script didn't take that into account, so triggered the jump animation twice.

avatar image
0

Answer by atcjavad · May 07, 2019 at 07:59 AM

Hi U need to connect all of your states to Exit State,Hi U need to connect all of your statments to Exit State.

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
  • 1
  • 2
  • ›

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

124 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 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

Animator Controller 2D RPG Best Practices 0 Answers

Animations not showing for Animator 0 Answers

how to get current gameObject animator triggers? 1 Answer

Animation not showing, but Animator running? 0 Answers

How to play an Animation only once from my MachineState Animator? 2 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