ValveSoftware / steam-audio

Steam Audio
https://valvesoftware.github.io/steam-audio/
Apache License 2.0
2.3k stars 159 forks source link

[Unity] Exception in StaticMesh constructor if Play Mode Scene Reload is disabled #219

Closed Matusson closed 1 year ago

Matusson commented 2 years ago

If Scene Reload is disabled in project settings, Static Meshes will not be loaded when entering Play Mode. Every frame, this exception is thrown:

NullReferenceException: Object reference not set to an instance of an object
SteamAudio.StaticMesh..ctor (SteamAudio.Context context, SteamAudio.Scene scene, SteamAudio.SerializedData dataAsset) (at Assets/Plugins/SteamAudio/Scripts/Runtime/StaticMesh.cs:71)
SteamAudio.SteamAudioStaticMesh.Update () (at Assets/Plugins/SteamAudio/Scripts/Runtime/SteamAudioStaticMesh.cs:55)

This seems to happen because the Scene reference passed to the constructor is null if this setting is disabled.

I've uploaded an example project: https://github.com/Matusson/SteamAudioReloadScene

To reproduce, clone and open the attached project, then load the ExampleScene scene and enter Play Mode. The exception should be thrown. Then go to Edit > Project Settings > Editor > Enter Play Mode Settings and toggle "Reload Scene". Now when you enter Play Mode, the exception should no longer occur. I've been able to reproduce this issue with Unity 2021.2.17f1 and 2021.3.8f1.

This is probably caused by some of the differences in behavior when disabling this setting, listed here: https://docs.unity3d.com/Manual/SceneReloading.html

Matusson commented 1 year ago

Confirmed fixed as of v4.3.0.