- Home /
Can't select function in Animation Event
I just want to play a sound (would be nice if the Audio thing had a Play event), anyway I made a little script, added it to my object. I can see the script and all in the Animation editor ok. I add an Animation Event where I want the sound to play. Note I have no compiler errors.
So it brings up the 'Edit Animation Event' dialog, but there are no functions to select! The only 'choice' I have is (no function selected). My script looks a lot like the one in the manual's example. It's JS:
private var sound : AudioSource;
function Start() { sound = GetComponent (AudioSource); }
function Play () { sound.Play(); }
What am I doing wrong, or is this a bug?
Happening to me too but nothing I do brings the selections back....Using 4.5.
This is out of Date for bug finding. Submit a fresh question, perhaps in the forum.
Answer by skovacs1 · Oct 18, 2010 at 09:09 PM
I tested what you describe and it worked perfectly fine. I cannot guess at what you have done wrong, but something about your description of your setup is missing. Maybe try a fresh scene and test what exactly you're doing. I created a cube, added a sound and attached the script "function Play(){audio.Play();}" I created an animation in the Animation window that went from position x = 0 at frame 0 to position x = 200 at frame 40. I added an AnimationEvent at frame 20 and I was able to set the function for the Event in the dialog to Play().
Creating a test worked ok, so I know it's not too broken. I deleted my object and recreated, that seemed to fix it. $$anonymous$$aybe I had wrong parenting or something. In any case, not an issue. Thanks.
Answer by Sylvanas · May 29, 2014 at 04:05 AM
I guess you maybe attached the script to the wrong place which should be attached to where the Animation component exists.
I had the same problem and this was the correct answer. The script needs to be attached to the object the animator component is on.
Answer by gsmetzer · May 29, 2014 at 01:58 AM
Happening to me too but nothing I do brings the selections back....Using 4.5.
This is happening to me too. I can see all the functions on that script in the list EXCEPT the one I want. However if I make a new object and animation the function is there.
Answer by Dream-Baked · Jul 16, 2014 at 09:57 PM
If there is an error in the Script file that holds the functions you are trying to call they wont show up.
Play your scene and if it fails to run because of errors, fix them. After that the functions will hopefully appear in the AnimatorEvent drop-down.
If your scene plays fine you probably haven't attached the script file to the GameObject you are animating.
Answer by Tony · Feb 05, 2011 at 01:39 AM
This appears to be a bug. Re-opening the scene solved this issue for me.