Hello, im trying to synchronice audio and animations.
Mainly attack animations and audio sounds.
So far i have a variable for animator.speed (float), and im thinking if there is any way to set an audio with the same length as the animation playing, and make both start at the same time and be modified in the same with speed.
How could i achieve that?
Is there a better way to do it?
You can use AnimationEvents. You stick them in your animations and they can call an arbitrary little snippet of code, and you can do stuff like play sounds.
https://docs.unity3d.com/Manual/animeditor-AnimationEvents.html
im trying to avoid animation events, because i have a lot of animations and it may take me alot of time to make animation events for all animations, because it takes 6-8 mins to load every time i modify something within the animations (i made the mistake of importing all animations in a single object)
also i dont really know how to call events to functions right now.
I’d recommend refactoring your anims so they’re more-easily importable! It sounds like it’s a tax on your workflow already, and that tax is only going to get more onerous as you try to add more stuff.
Barring that, you can’t really adjust the speed of the sound the way the animation does because that will change the pitch too.
Other approaches: make a simultaneously-playing ghost animation for each animation and put the events into that animation. Then you just have to make sure it plays every time the primary animation plays, and is adjusted to the same speed. That’s a yucky dirty hack which will also tax you long into the future.
Keeping the offset of where you intend to play the sound, then delaying by that amount multiplied by the speed of animation would give you an idea of when to play the sound, but that won’t work if you are continuously adjusting the speed throughout the anim before the sound hits.
In summary, I’d recommend deconflating your anims.