From 415d4881aab6369ad7fcd7640260db8d2b9f8dc2 Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Wed, 8 Jan 2025 02:11:14 +0900 Subject: [PATCH] Workaround Awaitable.Awaiter bug Using UnityEngine.Awaitable.Awaiter in Unity 2023.1 or newer. It has a bug that destroys ScriptableObject after await twice. This bug was reported. --- Tests/Runtime/AutopilotTest.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Tests/Runtime/AutopilotTest.cs b/Tests/Runtime/AutopilotTest.cs index 53c826a..1aebd55 100644 --- a/Tests/Runtime/AutopilotTest.cs +++ b/Tests/Runtime/AutopilotTest.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2023-2024 DeNA Co., Ltd. +// Copyright (c) 2023-2025 DeNA Co., Ltd. // This software is released under the MIT License. using System.Collections.Generic; @@ -195,9 +195,13 @@ public async Task Start_MappedSceneIsNotActiveButLoaded_DispatchAgent() const string MappedScenePath = TestScenePath; const string ActiveScenePath = TestScenePath2; + await SceneManagerHelper.LoadSceneAsync(ActiveScenePath); + await SceneManagerHelper.LoadSceneAsync(MappedScenePath, LoadSceneMode.Additive); + // Note: Workaround for destroy ScriptableObject after await twice bug. + Assume.That(SceneManager.GetActiveScene().path, Is.EqualTo(ActiveScenePath), "Mapped scene is not active"); + var spyMappedAgent = ScriptableObject.CreateInstance(); var spyFallbackAgent = ScriptableObject.CreateInstance(); - var autopilotSettings = ScriptableObject.CreateInstance(); autopilotSettings.sceneAgentMaps = new List { @@ -206,10 +210,6 @@ public async Task Start_MappedSceneIsNotActiveButLoaded_DispatchAgent() autopilotSettings.fallbackAgent = spyFallbackAgent; autopilotSettings.lifespanSec = 1; - await SceneManagerHelper.LoadSceneAsync(ActiveScenePath); - await SceneManagerHelper.LoadSceneAsync(MappedScenePath, LoadSceneMode.Additive); - Assume.That(SceneManager.GetActiveScene().path, Is.EqualTo(ActiveScenePath), "Mapped scene is not active"); - await Launcher.LaunchAutopilotAsync(autopilotSettings); Assert.That(spyMappedAgent.CompleteCount, Is.EqualTo(1), "Mapped Agent dispatched"); @@ -224,15 +224,15 @@ public async Task Start_NoMappedSceneInLoadedScenes_DispatchFallbackAgent() const string AdditiveScenePath = TestScenePath; const string ActiveScenePath = TestScenePath2; - var spyFallbackAgent = ScriptableObject.CreateInstance(); + await SceneManagerHelper.LoadSceneAsync(ActiveScenePath); + await SceneManagerHelper.LoadSceneAsync(AdditiveScenePath, LoadSceneMode.Additive); + // Note: Workaround for destroy ScriptableObject after await twice bug. + var spyFallbackAgent = ScriptableObject.CreateInstance(); var autopilotSettings = ScriptableObject.CreateInstance(); autopilotSettings.fallbackAgent = spyFallbackAgent; autopilotSettings.lifespanSec = 1; - await SceneManagerHelper.LoadSceneAsync(ActiveScenePath); - await SceneManagerHelper.LoadSceneAsync(AdditiveScenePath, LoadSceneMode.Additive); - await Launcher.LaunchAutopilotAsync(autopilotSettings); Assert.That(spyFallbackAgent.CompleteCount, Is.EqualTo(1));