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.

Audio in Unity "stacks" when game window is not in focus

0 votes
When running a build and tabbing away from the game window, the game continues silently, however during this time the audio event triggers will be stacking. When the game window regains focus, all these events will suddenly play together at the same time, up to around 600 of them which is the max queue limit. I can see them queuing in the Wwise profiler, but this isn't the behaviour I want. I have "Render During Focus Loss" checked in Unity, but the audio isn't playing/stopping as it should when the game window isn't in focus. I don't care if it's silent, I just want it to not stack and suddenly play masses of audio when you switch back to the window.
asked Sep 21, 2020 in General Discussion by Adam C. (120 points)

2 Answers

0 votes
Any solutions for this?
answered Apr 18, 2023 by Robert E. (550 points)
0 votes
For anyone who is encountering this issue and doesn't know how to solve it, one way (and the way I am currently using) is to use OnApplicationFocus(bool focus) which is a method accessible from any MonoBehaviour and lets you know when the application is focused or not (I.e. tabbed in) this way you could just choose not to play any new sounds when the user is tabbed out.

Docs for its use here: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnApplicationFocus.html
answered Jun 10, 2023 by John B. (140 points)
...