Audiokinetic's Community Q&A is the forum where users can ask and answer questions within the Wwise and Strata communities. If you would like to get an answer from Audiokinetic's Technical support team, make sure you use the Support Tickets page.

Is there a way to play or resume a sound depending on whether it has been previously played?

0 votes
Hi there :),

Pretty new to Wwise, so sorry if it's an obvious one. Essentially, here's my scenario: imagine one person is ringing a bell and another clashing swords. Depending on where the player looks I want the sounds to fade it, so if the player looks at the bell ringer then the ringing gets louder, and if he/she looks at the sword fighter both the bells fade out and the sword clashing fades in.

I've been following some Youtube tutorials on something similar (making a footstep sound only play when the player is moving, and also not while they are jumping) and it seems quite akin to my problem. However, the only difference is that I want it such that if the player has already looked at the bell ringer before, the bell sound fades in from where it previously faded out, NOT from the start of the sound. Is there a way to do this via Event Actions/any other ways?

I've tried setting the resume action, but as the sound hasn't actually played prior to this resume action taking effect nothing happens (which makes sense I guess since there's nothing to resume). I've also tried including both Play and Resume actions, but then whenever the user looks back to the bell the audios stack.

Thanks very much for any help,
asked Feb 26, 2017 in General Discussion by Ben M. (170 points)

1 Answer

+1 vote
Best answer
Keep these looping sounds continuing to play, i.e. so it does not actually "stop" when you look away, still playing but silent.  Trigger them only once or use instance limiting  Then you can simply fade in/out as needed.  Also, you can set it to use "virtual voices" if you want to keep the sound going without using up a voice.
answered Mar 2, 2017 by Monty M. (2,650 points)
selected Mar 14, 2017 by Ben M.
Hi Monty,

Thanks for the great suggestion! I really hadn't thought about doing that at all. So the way I've got it set up is as follows:

1. For each of these sounds (bell ringing, swords clashing etc) I have a PostEvent to trigger them

AkSoundEngine.PostEvent("bell_state", gameObject, (uint)AkCallbackType.AK_EndOfEvent, myCallbackFunction, this);

2. By default I couldn't actually find a way to mute these via code, so instead have defaulted to Pause using:

AkSoundEngine.ExecuteActionOnEvent("bell_state", AkActionOnEventType.AkActionOnEventType_Pause);

After testing it seems to do the job. How would you implement your suggestion, out of curiosity?

3. Then every time the player looks at the bells I just call:

AkSoundEngine.ExecuteActionOnEvent("bell_state", AkActionOnEventType.AkActionOnEventType_Resume, gameObject, 5000);

where 5000 is the fade in in millisecs.

In general, can you think of a cleaner way of doing this? It seems to work just fine, but if there's a better way of doing things I'd like to improve!

Thanks again for the help,
Another thing to consider perhaps is whether the sound needs to stay in sync with a looping animation?  Rather than pause/resume, adjust the sound objects' voice volume.  For more control, create an RTPC to drive whether you are looking at the object or even to what degree they are offscreen.  That would allow you to apply a curve to voice volume based on the RTPC.