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 Nanako · Mar 16, 2015 at 10:48 AM · animatorinterrupt

Animators, Animation Events, and Interrupting/Restarting

okay, here's the situation. My character can attack, by swinging his weapon. And once he starts an attack, i set the animator bool isAttacking to true. Thusly preventing the attack from being interrupted

Near the end of the attack animation, is an animation event. It calls a function which sets isAttacking to false, allowing farthere attacks to be done. I deliberately have this NEAR the end, not AT the end. so that there's a short period of relaxing back to normal stance where the animation is technically still playing, but as far as i'm concerned the attacking part of it is "done" and i want to allow more attacks to happen.

Now the problem is, if i spam click the attack button, it breaks. If i attack again during that winding-down period, isAttacking is set to true, but the attack animation is already playing, already past the ending point, and it does not restart. This causes me to get locked in a situation where i'm no longer attacking, but isAttacking is still set true and i can't start a new swing.

What i would like to happen is, if isAttacking is set to false, the attack animation starts anew, whether or not it's currently finished. How might i accomplish that? picture:

alt text

Comment
Add comment
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 Reply

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

Answer by Baste · Mar 16, 2015 at 01:01 PM

This is generally why you use triggers to fire off events in the animator instead of bools - triggers can be set before there's a state that's going to consume them that's active.

The setup with triggers is something like:

  • the animator goes from Default to Swing on the "Attack" trigger.

  • the animator goes from Swing to Default on exit time

  • the Swing animation has the animation event "AttackOver" close to the end.

Then your script could look like this:

 bool canAttack = true;
 
 void Update() {
     if(canAttack && Input.GetButtonDown("Attack")) {
         canAttack = false;
         animator.SetTrigger("Attack");
     }
 }
 
 void AttackOver() {
     canAttack = true;
 }





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 Nanako · Mar 16, 2015 at 01:10 PM 0
Share

huh? what is a trigger?

i'm looking at that in the animator now, it just looks like a bool with a different appearance What's the point of that?

avatar image Nanako · Mar 16, 2015 at 01:42 PM 0
Share

okay more importantly, how does this affect my problem at all? The issue is that the animation won't restart when the conditions are right. I don't see how changing those conditions is going to help.

avatar image Baste · Mar 16, 2015 at 01:46 PM 0
Share

It's really bad interface design that triggers and bools looks the same. Bad Unity, bad!

A trigger is like a single-use bool. You set it by using SetTrigger. Once it has activated, it stays true until it has fired a single transition. Then it resets back to false until you call SetTrigger again.

Check out the docs for an explanation.

avatar image Nanako · Mar 16, 2015 at 05:07 PM 0
Share

Okay thank you, i've implemented this. With this i was able to implement the transition as from anystate. seems to work as desired now

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

21 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

Related Questions

2D Animation does not start 1 Answer

Animatior Glitch when interrupted 0 Answers

How to interrupt ALL but one animation state? 0 Answers

Cancel current animation automatically and start it again when same animation triggered 2 Answers

Does anyone have an example of an animator with diagnol locomotion? 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