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 ZzYzXde · Sep 22, 2014 at 09:16 AM · mecanimanimation events

Animation event not always triggered

System: Unity 4.5.2

2d Game in c#

I have a character who throws his weapon in an animation. It is realized by two animation events. The first event detaches the weapon (throw) and the second creates the new instant of the weapon. While the animation is running a bool variable is set to false (readyToThrow - in the same methode as the throw animation is started) and is set back to true once the new weapon is created (second event). In rare cases the second event is not triggerd and the character has no weapon.

I tried to reproduce it in a small project. I used the 2D Platformer (https://www.assetstore.unity3d.com/en/#!/content/11228). I increased the 'Sample' from 3 to 60 in the animation clip Shoot and added two events.

I also added code:

 public class PlayerControl : MonoBehaviour
     {
         public bool isReady = true;
     
         public void EventShot1() {
             Debug.Log("EventShot1");
         }
         
         public void EventShot2() {
             Debug.Log("EventShot2");
             isReady = true;
         }
     }
     
     public class Gun : MonoBehaviour
     {
         void Update ()
         {
             // If the fire button is pressed...
             if(Input.GetButtonDown("Fire1") && playerCtrl.isReady)
             {
                 Debug.Log("Shot0");
                 playerCtrl.isReady = false;
                 // ... set the animator Shoot trigger parameter and play the audioclip.
             }
 }

How to reproduce:

You have to move continually left and right (alternately) and shoot as fast as possible. After a short time you can't shoot because is ready is false.

Log:

Massage: Amount:

Shot0 59

EventShot1 58

EventShot2 58

Probably fix:

Change animator from 'Animate Physics' to 'Normal'. I couldn't check my game atm.

Any help would be greatly appreciated.

Comment
Add comment · Show 1
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 b1gry4n · Oct 10, 2014 at 10:47 PM 0
Share

I dont like relying too much on animation driven events just because they can sometimes hiccup like this. I've found its much easier to just make your own "control" over the events by using a coroutine.

     void Update ()
     {    
         if(Input.GetButtonDown("Fire1") && playerCtrl.isReady)
         {
             playerCtrl.ThrowWeapon();
         }
     }
     //In the player control script...
     public bool isReady = true;
     public float throwTimer = 1.5f; // put whenever you want the throw to refresh, match the ti$$anonymous$$g up to your animation.
 
     public void ThrowWeapon(){ // this would be your EventShot1
         isReady = false;
         StartCoroutine(ThrowTimer());
     }
 
     IEnumerator ThrowTimer(){ 
         yield return new WaitForSeconds(throwTimer);
         isReady = true; // put EventShot2 here
     }

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Animation events firing all at once in mirrored blend tree 1 Answer

4.3, Animation Event in Animations from Mixamo 1 Answer

Mecanim animation layers and animation events 3 Answers

Mecanim animation events 2 Answers

Weapon System and Animation Events 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