I have an animation with animation events in an imported .fbx file. I spent some hours creating a class with delegates so that I could trigger methods on any C# class I wanted.

Now I wonder if that is necessary? Which types and methods does the animation event delegate a call to? Does it search through all fields, properties, containers etc in the GameObject with the Animator to find matching function names?

I found out unity has released a read-only version of their repository on github so I will dive in there and see if I can find what happens.

Ok I think it looks through all MonoBehavior based off the GetComponents on the GameObject with the Animator.

  • \$\begingroup\$ Your finding sounds consistent with the behaviour of SendMessage. Want to post it as an Answer below? \$\endgroup\$ – DMGregory Jun 12 at 7:32

My interpretation is that this code sets up the function calls: https://github.com/Unity-Technologies/UnityCsReference/blob/2019.4.0f1/Editor/Mono/Animation/AnimationWindow/AnimationWindowEventInspector.cs

In there it looks like the GameObject's GetComponents method is called. So that is probably how it works.

(I haven't read the entire context so not entirely sure but it sounds reasonable).

| improve this answer | |
  • \$\begingroup\$ Can you include the relevant excerpt of the linked code in your answer, so your reasoning isn't lost to future audiences if the repository ever changes URL or goes offline? \$\endgroup\$ – DMGregory Jun 12 at 11:44
  • \$\begingroup\$ I don't want to risk it, it was hard to understand the copyright notice. Also, I didn't find any "playmode loop", so I am not sure this is the right place to look. But it was a pretty straightforward function which iterated over GetComponents and used reflection to check the function signatures. "CollectSupportedMethods" is the one I looked at. \$\endgroup\$ – Emil Jun 12 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.