1

I've integrated Wwise (2022.1.0) in a Unity (2022.1.1) project. When I start the game I can play sounds from Wwise but I get the following error. I searched for solutions but couldn't find anything. Seems like the AkWwiseProjectData.asset which stores some data is a temporary cache file.

WwiseUnity: Unable to load Wwise Data: UnityEngine.UnityException: LoadAssetAtPath can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function. at (wrapper managed-to-native) UnityEditor.AssetDatabase.LoadAssetAtPath(string,System.Type) at UnityEditor.AssetDatabase.LoadAssetAtPath[T] (System.String assetPath) [0x00001] in /Users/bokken/buildslave/unity/build/Modules/AssetDatabase/Editor/ScriptBindings/AssetDatabase.bindings.cs:233 at AkWwiseProjectInfo.GetData () [0x0001a] in /Users/studio/Game/Assets/Wwise/API/Editor/WwiseWindows/AkWwiseProjectInfo.cs:72 UnityEngine.Debug:LogError (object) AkWwiseProjectInfo:GetData () (at Assets/Wwise/API/Editor/WwiseWindows/AkWwiseProjectInfo.cs:95) AkWwiseTreeProjectDataSource:SaveExpansionStatus (System.Collections.Generic.List`1) (at Assets/Wwise/API/Editor/WwiseWindows/AkWwiseTreeProjectDataSource.cs:284) AkWwiseTreeView:SaveExpansionStatus () (at Assets/Wwise/API/Editor/WwiseWindows/AkWwiseTreeView.cs:128) AkWwiseTreeView:Finalize () (at Assets/Wwise/API/Editor/WwiseWindows/AkWwiseTreeView.cs:872)

And here is the method that I am sent to

public static class AkWwiseProjectInfo
{

...

public static AkWwiseProjectData GetData()
    {
        if (ProjectData == null && WwiseFolderExists())
        {
            try
            {
                ProjectData = UnityEditor.AssetDatabase.LoadAssetAtPath<AkWwiseProjectData>(s_dataAssetPath);

                if (ProjectData == null)
                {
                    var dataAbsolutePath = System.IO.Path.Combine(UnityEngine.Application.dataPath, s_dataRelativePath);
                    var dataExists = System.IO.File.Exists(dataAbsolutePath);
                    
                    if (dataExists)
                    {
                        UnityEngine.Debug.LogWarning("WwiseUnity: Unable to load asset at <" + dataAbsolutePath + ">.");
                    }
                    else
                    {
                        var dataAbsoluteDirectory = System.IO.Path.Combine(UnityEngine.Application.dataPath, s_dataRelativeDirectory);
                        if (!System.IO.Directory.Exists(dataAbsoluteDirectory))
                            System.IO.Directory.CreateDirectory(dataAbsoluteDirectory);
                    }

                    CreateWwiseProjectData();
                }
            }
            catch (System.Exception e)
            {
                UnityEngine.Debug.LogError("WwiseUnity: Unable to load Wwise Data: " + e);
            }
        }

        return ProjectData;
    }

...

}
Ando
  • 1,802
  • 4
  • 25
  • 47
  • Could you include more code and how exactly `GetData` is called? Error messages sounds quite self-explanatory: It is being called on a separate thread -> Most of Unity API can only be used on the Unity "main" thread -> Make sure you call your stuff on that Unity main thread – derHugo Aug 02 '22 at 07:35
  • See e.g. [here](https://stackoverflow.com/questions/68651976/invoking-a-function-in-main-thread-via-background-thread-in-unity), [here](https://stackoverflow.com/questions/41330771/use-unity-api-from-another-thread-or-call-a-function-in-the-main-thread) or [here](https://stackoverflow.com/questions/58469468/what-does-unitymainthreaddispatcher-do) .. all using something like [UnityMainThreadDispatcher](https://github.com/PimDeWitte/UnityMainThreadDispatcher) – derHugo Aug 02 '22 at 07:37
  • Hello @derHugo. I am not calling the `GetData` method. It's being called by the Wwise library, or so I assume. I don't think the problem is in my code as much as the integration of Wwise with Unity. That's the reason I posted my question here. Perhaps someone has had this problem or is aware of what could be the cause of it. – Ando Aug 02 '22 at 08:21
  • I think the error and I already told you what the issue is ;) And I provided links for how this can be addressed. If this is not your own code then yes the creator of it screwed this up and would need to fix it accordingly ;) – derHugo Aug 02 '22 at 08:57

0 Answers0