- Home /
"objectName AnimationEvent 'methodName' has no receiver! Are you missing a component?"
I'm making an animation that has an animation event at the end of every loop that calls a function in a script. But I keep getting that error when they loop, and yes, I assigned the script to the animation event in the Inspector.
void IncrementAnimationTimer()
{
StartCoroutine(WaitForABit());
}
IEnumerator WaitForABit()
{
yield return new WaitForSeconds(2.0f);
anim.SetInteger("Counter", Counter);
}
Have no idea what's happening here, maybe I need to assign something else in the Inspector?
Answer by Chimer0s · Feb 07, 2019 at 10:20 PM
That error means that the object with the Animator that calls the event doesn't have the script attached that contains that function. Any chance you forgot to place the script on the gameobject?
Edit: I should clarify how the fields of the event window work to avoid future confusion, as well. The fields below function are for passing values to that function, i.e. for instantiation. Say you wanted to instantiate a prefab with a function like CreateObject(GameObject thingToInstantiate). In the event window you would put "CreateObject" in the Function field and the prefab in the Object field. Then the receiver would have the function called with the prefab passed as the GameObject value thingToInstantiate. The only way this works, though, is if the gameobject with the Animator attached also has the script with the function attached. That's where it gets the reference from.
@Chimer0s Thank you! What happened was that there were 4 game objects. 3 of them were having the function called no problem (but my function didn't work) and one that was a little different from the others (not having the appropriate script as you said) pumping out an error. So I though all of them were malfunctioning because my function wasn't working correctly and one was pumping out an error. Again, thank you so much!
Answer by $$anonymous$$ · Feb 06, 2019 at 11:49 PM
I don't know the full context of this, but if it says it has no receiver, then it has no receiver. I suggest using Debug.Log to find out why the receiver isn't being set.
Thanks for the suggestion. Basically, I wanted an animation to loop but with a few seconds in between (without animating that delay itself). I made a function that starts a coroutine which counts a few seconds and resets and blah blah blah, and at the end of every loop there is an animationEvent that executes that function, but I keep getting this. Also, I've tried the debug.log and it prints the message but still gives the error... interesting