James Richter
Guest
Posts: 0
|
Post by James Richter on Jul 22, 2016 16:10:39 GMT
What is the method for triggering a sound with an Animation Event? For this project I'm having to use the Animation Import Settings interface: docs.unity3d.com/Manual/AnimationEventsOnImportedClips.html. What Function name do I need to give to tie the Animation Event to the Event Sounds script I've added?
|
|
|
Post by DarkTonic Dev on Jul 22, 2016 19:52:39 GMT
I haven't used those before. They look "legacy" to me. Anyway, there's currently no way in EventSounds to do anything with that, unless you want to fire a Custom Event and listen for the Custom Event on the EventSounds. You may need to call the API directly if you know how to execute code from an animation event. If you come up with something usable, send it to me and I can consider including it a the future update.
We do use the MechanimStateSounds script to play a sound when a Mechanim State is entered and/or exited. Will those work for your purpose? If so, why not?
|
|
James Richter
Guest
Posts: 0
|
Post by James Richter on Jul 22, 2016 22:08:34 GMT
It's a looping clip with 2 events, one at frame 10 and another at frame 22. I could use the Mechanim thing on delays, but that's broken as soon as somebody changes the animation speed. We have a programmer so I'll see if he can figure it out with the API.
|
|
|
Post by DarkTonic Dev on Jul 22, 2016 23:51:30 GMT
I see, ok. If you can show me to call *any UNITY method* from frame 10, maybe I can assist. Like I said, I haven't done those before.
|
|
James Richter
Guest
Posts: 0
|
Post by James Richter on Aug 8, 2016 17:32:28 GMT
To follow up: our programmer was able to get this going. He added the following at the end of a script that lives on all anims in our game: /// <summary> /// Function reacts to various custom animation events. /// </summary> /// <param name="eventName">Name of the event to trigger</param> public void AgentAnimationEvent(string eventName) { MasterAudio.FireCustomEvent(eventName, transform.position); } Now when I add an Animation Event, I plug AgentAnimationEvent into the Function field and the Custom Event name into the String field, and the magic happens (provided I've defined the Custom Events in an Event Sounds component on the animated object, of course).
This is a common enough implementation method in my projects that I'd like to see you add it to future releases of Master Audio (and spell out how to use it in the documentation). Maybe an OnAnimationEvent category under the MonoBehavior events?
Thanks for being a friendly, quick responder to your forums!
|
|
|
Post by DarkTonic Dev on Aug 8, 2016 19:49:33 GMT
Sorry but I don't understand what that code is doing out of context. I would need the whole file probably. Maybe you can have your programmer get in touch with me through email?
Jerotas2005@yahoo.com
|
|
Digital Iris Games
Guest
Posts: 0
|
Post by Digital Iris Games on Apr 30, 2021 2:05:57 GMT
I know this thread is old but did the poster ever send the related info in email or did it get investigated further? We are trying to accomplish something similar. We are using a Blend Tree for our character animations and Master audio does not attach to animations in the Blend Tree so wee need another solution. Thank you.
|
|
|
Post by DarkTonic Dev on Apr 30, 2021 2:12:52 GMT
I don't believe they did get in touch with me after this.
You do know that you can add the Mekanim State Sounds script to any state in mekaninm right? If you don't use mechanim or want to play a sound from a particular frame in your animation there is also a way to do that, which I can point you to if that's what you're trying to do.
Other than that there is no specific support for animations. You would need to write your own code. I have no idea how to use a blend tree and even when I watch videos about that it makes my brain explode.
-B
|
|
Digital Iris Games
Guest
Posts: 0
|
Post by Digital Iris Games on Apr 30, 2021 13:58:52 GMT
Thanks for the quick reply. We'll look at writing our own code but I am interested in the idea of playing a sounds based on animation frame too. Please do point me to that information. Thanks!
|
|
|
Post by DarkTonic Dev on Apr 30, 2021 16:24:06 GMT
|
|
Digital Iris Games
Guest
Posts: 0
|
Post by Digital Iris Games on Apr 30, 2021 18:44:38 GMT
Excellent. Thank you!
|
|
|
Post by DarkTonic Dev on Apr 30, 2021 18:51:07 GMT
No problem.
|
|