Unity has no receiver ошибка

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:
enter image description here

To fix this, I bubbled-up the event from the child gameobject to the parent:
enter image description here

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 /

avatar image

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!

avatar image

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

avatar image

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 ;-)

avatar image

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;

avatar image

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).

avatar image

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!

avatar image

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

avatar image

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 ;-)

avatar image

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;

avatar image

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).

avatar image

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 зачем нужно?

alexsilent 25 май 2012, 03:39

Пытаюсь добавить куда-нить строчку:
SendMessageOptions.DontRequireReceiver;

но компилятор на нее ругается
Assets/MY SCRIPTS/Global.js(8,20): BCE0034: Expressions in statements must only be executed for their side-effects.

я уже все варианты попробовал наверное, добавлял в Awake(), в Update(), вообще в инициализацию переменных, и все время одна и та же ошибка.

alexsilent
UNIверсал
 
Сообщения: 440
Зарегистрирован: 21 май 2011, 10:30

Re: SendMessageOptions.RequireReceiver зачем нужно?

Сообщение IDoNotExist 25 май 2012, 04:44

alexsilent писал(а):Нашел в документацию опцию,

И что неужели там примера нету вот например здесь полное описание функции, что и куда вставлять написано.
RequireReceiver означает что обязательно должен быть приемник сообщения (функция которую оно вызывает), DontRequireReceiver соответственно что приемник не нужен, отправили сообщение и забыли, прописывать его нужно естественно в последнем аргументе функции SendMessage(), т.е. SendMessage(«func_blablabla», arg1, SendMessageOptions.DontRequireReceiver).

Аватара пользователя
IDoNotExist
Адепт
 
Сообщения: 1432
Зарегистрирован: 23 мар 2011, 09:18
Skype: iamnoexist

Re: SendMessageOptions.RequireReceiver зачем нужно?

Сообщение alexsilent 25 май 2012, 05:34

IDoNotExist писал(а):

alexsilent писал(а):Нашел в документацию опцию,

И что неужели там примера нету вот например здесь полное описание функции, что и куда вставлять написано.
RequireReceiver означает что обязательно должен быть приемник сообщения (функция которую оно вызывает), DontRequireReceiver соответственно что приемник не нужен, отправили сообщение и забыли, прописывать его нужно естественно в последнем аргументе функции SendMessage(), т.е. SendMessage(«func_blablabla», arg1, SendMessageOptions.DontRequireReceiver).

оу спасибо! Теперь все встало на свои места! Я не внимательно смотрел на саму функцию

alexsilent
UNIверсал
 
Сообщения: 440
Зарегистрирован: 21 май 2011, 10:30


Вернуться в Почемучка

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 23



Понравилась статья? Поделить с друзьями:
  • Uninstallshield уже используется ошибка 432
  • Uninstallshield ошибка 432 при установке игры
  • Unindent does not match any outer indentation level ошибка
  • Unifr dll 3651 ошибка 200 логическая ошибка 0xc8
  • Uniform 01 division 2 ошибка