I had the same error, but with a different cause and solution.
All my code was in a (grand)parent gameobject (e.g. WerewolfPlayer) and I wanted to keep it this way. The animator was in a (grand)child gameobject (e.g. WEREWOLF_PBR) and it couldn’t find the animation events:
To fix this, I bubbled-up the event from the child gameobject to the parent:
I edited the PlayerController.cs in the parent gameobject (e.g. WerewolfPlayer) to find the new «hand off animation events» script and fire the animation events when they happen:
using UnityEngine;
using System;
public class PlayerController : MonoBehaviour
{
private HandOffAnimationEvent handOffAnimationEvent;
// called when animation event fires
public void Pickup()
{
Debug.Log("player picks up object here...");
}
void OnEnable()
{
handOffAnimationEvent = GetComponentInChildren<HandOffAnimationEvent>();
handOffAnimationEvent.OnPickup += Pickup;
}
void OnDisable()
{
handOffAnimationEvent.OnPickup -= Pickup;
}
}
The new HandOffAnimationEvents.cs was added to the child gameobject (e.g. WEREWOLF_PBR) and when the animation event fires, it fires its own event:
using UnityEngine;
using System;
public class HandOffAnimationEvent : MonoBehaviour
{
public event Action OnPickup;
// This is the animation event, defined/called by animation
public void Pickup()
{
OnPickup?.Invoke();
}
}
- Spaces
- Default
- Help Room
- META
- Moderators
-
- Topics
- Questions
- Users
- Badges
- Home /
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!
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.
robhuhn
raybarrera
mcroswell
erebel55
DChap
http://forum.unity3d.com/threads/19597-AnimationEvent-help-Solved
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
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;
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).
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 )
Unity Answers is in Read-Only mode
Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.
For more information and updates, please read our full announcement thread in the Unity Forum.
Follow this Question
Related Questions
Go to Unity3D
r/Unity3D
r/Unity3D
News, Help, Resources, and Conversation. A User Showcase of the Unity Game Engine.
Members
Online
•
by
witcherknight
Animation event has no receiver error
I have created an animation even called BeginAttack. but whwnever i play attack animation i am getting Animation event has no receiver error. What am i doing wrong??
In the process of editing animation by unity, this prompt always appears:
AnimationEvent ‘XXXXXX’ on animation ‘XXXXXX’ has no receiver! Are you missing a component?
After a long time, I changed the value, but it didn’t work
Hang the script of the method you want to execute on the object you want to execute the animation, and that’s it!
Yes, it’s that simple. But waste me a long time!!!
Read More:
SendMessageOptions.RequireReceiver зачем нужно? [Решено]
Когда я посылаю SendMessage объекту, то приходит вот такая вот ошибка
SendMessage GetThatItem has no receiver!
я не понял, кажется у меня раньше не было такой ошибки никогда, что значит не имеет Receiver (применика)?
Насколько это критично? Для чего это вообще? Что за Receiver (приемник)?
Нашел в документацию опцию,
SendMessageOptions.DontRequireReceiver
я так понимаю ее надо только в одном экземпляре использовать на всю игру вначале инициализации?
надеюсь ничего критичного не будет
Последний раз редактировалось alexsilent 25 май 2012, 05:35, всего редактировалось 1 раз.
- alexsilent
- UNIверсал
- Сообщения: 440
- Зарегистрирован: 21 май 2011, 10:30
Re: SendMessageOptions.RequireReceiver зачем нужно?
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!
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.
robhuhn
raybarrera
mcroswell
erebel55
DChap
http://forum.unity3d.com/threads/19597-AnimationEvent-help-Solved
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
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;
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).
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 )
Unity Answers is in Read-Only mode
Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.
For more information and updates, please read our full announcement thread in the Unity Forum.