Animation Events taking a Component Reference

I have created an animation event and attached a function which accepts an “Audio Source” component reference. The functions purpose is to play the “Audio Source” on the event trigger. However, the only selectable “Audio Source’s” are in the Project view, not the Scene Hierarchy. So two questions:-

  1. Why do the animation events only allow project references?
  2. Selecting an audio source (from a prefab) doesn’t work as the audio source is considered disabled, as it is not loaded in the scene hierarchy. Any ideas on the correct method?

Cheers for any help, at this rate i’m going to end up hard coding my audio in script.

P.S. Why is it so hard to trigger audio in an animation?

You do not specify if you are using Mecanim or Legacy, so in the future please be a little clearer on that. I am assuming Legacy because that is the one that can select specific functions in the animation events.

You can not choose an Audio Source (or any other object from the scene) in a function parameter for an Animation Event because the event is stored on the animation and the animation is stored in the Project and not in the Scene. As with prefabs they can then not have a reference to a scene object because there are no guarantee that the object will be there (for example when another scene is running).

There are many ways of playing a specific audio on an animation. One could be to have a sort of AudioManager in your scene which references all the audio in a list, and have the function called by the animationevent use an int parameter for specifying which audio in the AudioManager to play.