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 Destoffe · Jun 26, 2015 at 02:20 PM · animationanimatorbooleanstuckparameters

Animator parameter stuck as True

Hi! I'm using the animator controller for my "attack" animation. It works like a charm if i press the button that's supposed to trigger the animation in a gentle speed like once every second. But if i happen to spam press the button let's say 3 times a second the parameter im using gets stuck as True and the animation gets stuck at the last frame of my attack Animation and wont return to Idle.

 if ((Input.GetKey (KeyCode.V)) && !anim.GetBool ("Attack"))
             anim.SetBool ("Attack", true);

Here's the code i use to trigger the attack animation, i have an Animation event at the last frame of my attack animation to set the Bool back to false so he will return to idle again.

 void StopAttack()
     {
         anim.SetBool ("Attack", false);
     }
Comment
Add comment · Show 5
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 DiegoSLTS · Jun 26, 2015 at 03:50 PM 0
Share

Please, show us how the transitions to and from the attack state are configured.

avatar image Landern · Jun 26, 2015 at 04:12 PM 0
Share

@DiegoSLTS, I removed that answer, my count was off this morning and you're right, made no difference.

avatar image Destoffe · Jun 26, 2015 at 04:18 PM 0
Share

Im sorry if im frustrating now but how would a picture with good information about the transitions look like?

avatar image The_Guy · Jun 26, 2015 at 04:34 PM 0
Share

try changing it to Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.V) and see if that helps any.

avatar image Destoffe · Jun 26, 2015 at 05:19 PM 0
Share

I now noticed that it happens if i hold down the key for 2-3 seconds it gets stuck. Do i need some kind of if statement like Get$$anonymous$$eyUp to make it true aswell perhaps?

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by hnmikechan · Jun 26, 2015 at 08:46 PM

I like putting my event handlers for functions similar to the StopAttack() at frame 1 or 2 of an animation. I don't think there is a reason to call it at the end. Once the transition is triggered there is no reason to keep the condition bool on.

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 The_Guy · Jun 26, 2015 at 05:35 PM

Okay, I think this will help. Set up your animator like this:alt text

Add the "isAttacking" bool to your parameters in the top left of the animator panel. Make sure there are arrows to and from Idle and Attack. Then select the attack state and look in the inspector. alt text

Do the same for the Idle state except isAttacking would be false.

Then have your code like this:

 if ((Input.GetKeyDown (KeyCode.V)) && !anim.GetBool ("isAttacking"))
             anim.SetBool ("isAttacking", true);

and use however you did to set isAttacking to false again.


exampl2.png (45.4 kB)
example1.png (24.8 kB)
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 Destoffe · Jun 26, 2015 at 05:47 PM 0
Share

The thing is, this is exactly how it is when it's causing the problem..

avatar image The_Guy · Jun 26, 2015 at 05:55 PM 0
Share

hmm, well idk what kind of game you are making but maybe implementing a cooldown timer would work. something like

 bool canAttack = true;
 float attackTimer = 0;
 public float attackCooldown;
 ..........
 if ((Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.V)) && !anim.GetBool ("isAttacking") && canAttack){
     attackTimer = 0;
     canAttack = false;            
     anim.SetBool ("isAttacking", true);
 }
 .........
 Update(){
     if(!canAttack){
         attackTimer += Time.deltaTime;
         if (attackTimer > attackCooldown) canAttack = true;
     }
 }
              
  
avatar image Destoffe · Jun 26, 2015 at 06:02 PM 0
Share

It's a topdown 2D game, it's just a very simple attack animation and i dont get how other people havn't had this problem..

avatar image patosalas Destoffe · Aug 29, 2016 at 06:18 PM 0
Share

I am having the same problem right now!

avatar image
0

Answer by kathy12345 · Sep 16, 2016 at 11:38 AM

Mine was stuck on true because I had forgotten to add a Condition in the inspector panel for the 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
avatar image
0

Answer by yourecrippled · Mar 17, 2017 at 02:25 PM

animator controller > click on state > uncheck "write defaults"

I did this to all states in my animation controller. It worked for me.

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

9 People are following this question.

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

Related Questions

Play animation while button is pressed fails when using boolean parameters. 1 Answer

Blend Tree Transition Conditions. 0 Answers

Stop Animation State in Animator from Speeding Up after Playing it a Second Time? 0 Answers

What is the proper way to organize animator transitions to a large amount of abilities? 0 Answers

Double collision on "ground" tagged object results in player thinking they're in air? 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