• 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 jackpile · Sep 11, 2011 at 07:47 AM · animationevent

AnmationEvent has no receiver! error

I have a GameObject that adds an AnimationEvent to a clip that calls a function at completion of the animation. It calls this function reliably -- until I destroy the game object. I destroy the object when I detect a collision and I am careful to call Animation.Stop() before I destroy the object, so the end function callback should not be called, but appears to be. My worry is that Unity might still try to call the function even if I stop the animation early, but by that time the object is gone.

The relevant code:

 function BeginIdleAnimation() {
     if (idleAnimation) {
         var repeat : boolean = idleAnimation.wrapMode == WrapMode.Loop 
             || idleAnimation.wrapMode == WrapMode.PingPong;
         PlayAnimationClip(idleAnimation, repeat ? "IdleAnimDone" : null);
         PlayClip(idleSound);
     }
 }
 
 function PlayAnimationClip(clip : AnimationClip, endFunc : String) {
     if (clip) {
         // create event that calls desired endFunc when animation completes
          if (endFunc) {
              var event : AnimationEvent = new AnimationEvent();
               event.functionName = endFunc;
               event.time = clip.length; 
                clip.AddEvent(event);
            }
         animation.clip = clip;
         animation.Play();
     }
 }
 
 // Here's the relevant snippet of collision code that supposedly stops the animation before destroying itself...
 
 function OnCollision(p : Projectile) {
     if (p) {
         animation.Stop();
         Destroy(transform.parent.gameObject);
     }
 }
 
 function IdleAnimDone() {
     PlayClip(idleSound);
 }
 

I get "AnimationEvent 'IdleAnimDone' has no receiver!" error.

Thanks in advance!

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

5 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by 3Duaun · Sep 14, 2011 at 11:37 PM

oddly enough, AnimationEvent seems to use SendMessage, and CANT send AnimationEvent Calls to an animation component on a different object(in the hierarchy). You MUST, apparently, from the bit I researched( I could be wrong, but just reproduced this error and fix in a test scene), issue those AnimationEvent calls to an animation component(holding your anim clips) on the same object as the script issuing the AnimationEvent calls.

Comment
Add comment · Show 1 · 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 3Duaun · Sep 14, 2011 at 11:38 PM 0
Share

http://forum.unity3d.com/threads/19597-AnimationEvent-help-Solved

avatar image
2

Answer by 3Duaun · Sep 21, 2011 at 02:57 AM

Make your animation event call on the SAME object that has the ANIMATION COMPONENT you are adding the events to, and then you dont need to perform the dontRequireReceiver option as well. SendMessage can have requirements on which direction in the hierarchy it will send the message to ;-)

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
1

Answer by jackpile · Sep 20, 2011 at 11:28 PM

It pays to read the documentation, huh? This solves the problem:

AnimationEvent ae = new AnimationEvent(); ae.messageOptions = SendMessageOptions.DontRequireReceiver;

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 GordonLudlow · Aug 16, 2012 at 02:11 AM

Another way this can happen is if the component is removed from the animated object (or someone on your team doesn't check the addition of the component to the prefab into version control but does check in the animation change).

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 RKSandswept · Sep 10, 2014 at 09:32 PM

I noticed that when it put my event in the top event field it added in

protected virtual void OnAttack( string attackType )

but had the word NewEvent in front. So it was

NewEvent protected virtual void OnAttack( string attackType )

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

AnimationEvent triggered multiple times? 1 Answer

problems with pressing a button to run the animation. 0 Answers

Keep boolean true whilst playing animation, then false 1 Answer

Problem with Animation Event 0 Answers

Animation Plays well,but teleportation effect happens briefly when parenting the object to other obj 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