Sign in to follow this  
Alundra

Animation footstep event to play sound : multiple sound issue

Recommended Posts

Hi,
When you set your events in the animation and then the event callback is called to play the sound, since you blend 2 animations from the 4 (North/South/East/West), you have 2 sounds played the same time.
The only good way I found to avoid this issue is to change one boolean "PlayFootstepSound" in the callback and then in the update play the sound if the boolean is true.
Is there a safe way to avoid this issue without this boolean method ?
Thanks

Edited by Alundra

Share this post


Link to post
Share on other sites

Engines usually have features to deal with this, such as only playing notifies for the highest weighted animation, but you can usually easily edit your callback code to only play a sound if it's not already been played in the last frame. In Unity you could set a flag to play a sound in the callback and then play the sound in LateUpdate, clearing the flag afterwards.

Share this post


Link to post
Share on other sites

The method using the threshold of the blending weight of the animation, which is a common solution, can gives you the same issue with a blend at 0.5 because if you test if the weight is < or > than 0.5 you then get 0 event sent and if you check if the weight is <= or >= you end with the two events sent again.

Edited by Alundra

Share this post


Link to post
Share on other sites

s there a safe way to avoid this issue without this boolean method ?

what behavior do you want?

* play footfall if any blended animation calls for it, but only if footfall is not already playing? for that you can just check is_playing() and if its false, fire off the sfx right then. no deferred processing (and accompanying flags) required.

* play footfalls of animation with highest weight? again, you can fire off the sfx as soon as you have the weights. first found should be adequate for tie-breaking.

 

The boolean method (code pattern) you describe can be useful as an alternative way to code complex "if A or B or C or ..." type statements. as in: bool=0, if (A) bool=1; if (B) bool=1; ...   if (bool) { do_something }

use of the bool seems to have more to do with the fact that you determine whether to play a footfall during animation blending, but defer the playing of the SFX until update - IE deferred as opposed to immediate processing. deferred processing always requires at least one extra variable to indicate whether deferred processing should occur or not. obviously, you want to immediately process everything you can, and only defer what you must, as deferred is somewhat more work to implement, creates somewhat more complex code where processing is spread across the code instead of being done all in one place,  and incurs a slight performance penalty in both speed and ram.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this