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.

[Unity, bug] Wwise 2021.1.1 making game stutter/slow down FPS if "Reload Domain" is disabled

+1 vote
Tested with:
Wwise 2021.1.1.7601
Unity 2021.1.1f1
Wwise Integration 2021.1.1.7601.2102
Checking Unity game's FPS via the Unity Stats window (recent Unity versions display accurate FPS values)
Windows 10

After I upgraded Wwise to 2021.1.1, if I enable Unity's "Enter Play Mode Options" and disable the "Reload Domain" option, when I enter Play Mode the Unity game noticeably starts stuttering, and the FPS will drop, compared to when Reload Domain is enabled.
Even worse, each time I exit and enter Play Mode again, the game will stutter and the FPS will drop even more.
I guess some static fields or static event handlers from Wwise 2021 aren't being properly cleared when Domain Reload is disabled. Then, they keep accumulating in each Play Mode and thus making the FPS drop more and more.

Unity reference for supporting "disabled Domain Reload":
https://docs.unity3d.com/Manual/DomainReloading.html

This issue doesn't happen if "Reload Domain" is enabled, or if the "Enter Play Mode Options" are disabled.
But I'd expect for Wwise 2021 to be compatible even when Reload Domain is disabled, because this setting is a huge timesaver for lots of Unity users, and Wwise 2019 didn't suffer from this issue (see below).

Before upgrading Wwise to 2021.1.1, I used Wwise 2019.2.9.7459.
In this older version, the FPS bug doesn't happen. The Unity project still maintains its original FPS and doesn't stutter, even if "Reload Domain" is disabled.
asked May 25, 2021 in General Discussion by Andrei M. (720 points)

2 Answers

+1 vote

EDIT: This fix was tested in Wwise Integration 2021.1.1.7601.2102.
If you're using a more recent Wwise Integration version, check out my other answer with a slightly modified fix.


I managed to solve my issue by modifying two classes, to ensure certain events are always unregistered (and weren't being accumulated) at each Play Mode.

The main optimization was in AkWwiseFileWatcher.cs (from Wwise\API\Runtime\Handwritten\Common), I added the following lines:

// Inside "public void StartWatchers()" method

WwiseProjectUpdated -= AkUtilities.SoundBankDestinationsUpdated; // Added line
UnityEditor.EditorApplication.update -= OnEditorUpdate;          // Added line
      
WwiseProjectUpdated += AkUtilities.SoundBankDestinationsUpdated;
UnityEditor.EditorApplication.update += OnEditorUpdate;

I also did another small optimization at AkSoundEngineController.cs (from Wwise\MonoBehaviour\Runtime), I added the following line in two parts of the Init() method, just to be sure:

// Inside "public void Init(AkInitializer akInitializer)" method
// There are two lines in that method written as: "UnityEditor.EditorApplication.update += LateUpdate;"
// Just above each of them, I added the following line:

UnityEditor.EditorApplication.update -= LateUpdate; // Added line
UnityEditor.EditorApplication.update += LateUpdate;

There are some static fields/event handlers in other classes from the Wwise Integration code, that could possibly also benefit from similar optimizations.
But for now, optimizing these two classes was enough for my needs.

answered May 25, 2021 by Andrei M. (720 points)
edited Apr 3, 2022 by Andrei M.
+1 vote

I recently upgraded Wwise Integration to version 2021.1.7.7796.2335.
On this version, I still have to make a few code modifications, to clear some static event handlers and avoid the FPS drops when entering Play Mode, while Domain Reload is disabled.

The AkWwiseFileWatcher.cs modification (the main optimization) is the same as I described before:

// Inside "public void StartWatchers()" method

WwiseProjectUpdated -= AkUtilities.SoundBankDestinationsUpdated; // Added line
UnityEditor.EditorApplication.update -= OnEditorUpdate;          // Added line
      
WwiseProjectUpdated += AkUtilities.SoundBankDestinationsUpdated;
UnityEditor.EditorApplication.update += OnEditorUpdate;

The AkSoundEngineController.cs modification was changed to:

public void EnableEditorLateUpdate()
{
    DisableEditorLateUpdate(); // Added line
    UnityEditor.EditorApplication.update += LateUpdate;
}
answered Apr 3, 2022 by Andrei M. (720 points)
...