Animation Event Function

We try to keep our project structure as clean as possible, so I was wondering, if I need to call a function from an animation using animation event, the script file needs to be in the same object that has the animator (so far this worked).

Can I reference a script that’s somewhere else? If so, how?

For example, right now I got my GameSounds script, that has the function playfootstep on the same object that has the animator component, but I would love to be able to have the GameSounds script located into a separate GameSounds object that I could use somewhere else.

Thanks in advance!
JP

Nope! Has to be the same object.

I find that the easiest way to handle animation events is with a script that picks up the events, which relays them to the correct components.

You can have an animation event call a function that sends a UnityEvent. Then any listeners on any other gameobject can respond to the event. Very loosely coupled.

1 Like

Hmmmm yeah, I guess that makes sense. Still. It’s weird that you have to create a script attached to the object in order for it to work, instead of just referencing it, or receiving the event from the outside.

1 Like