Skip to content

Commit 9c76ae2

Browse files
committed
Fix some AsyncCoroutineRunner related issues
1 parent 687ea6b commit 9c76ae2

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

Assets/MRTK/Core/Utilities/Async/AwaiterExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ private static void RunOnUnityScheduler(Action action)
145145
}
146146
else
147147
{
148+
var _ = AsyncCoroutineRunner.Instance;
148149
AsyncCoroutineRunner.Post(action);
149150
}
150151
}

Assets/MRTK/Core/Utilities/Async/Internal/AsyncCoroutineRunner.cs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,19 @@ internal static AsyncCoroutineRunner Instance
5656

5757
if (instance == null)
5858
{
59-
var instanceGameObject = GameObject.Find("AsyncCoroutineRunner");
59+
instance = FindObjectOfType<AsyncCoroutineRunner>(true);
6060

61-
if (instanceGameObject != null)
61+
if (instance != null)
6262
{
63-
instance = instanceGameObject.GetComponent<AsyncCoroutineRunner>();
64-
65-
if (instance == null)
66-
{
67-
Debug.Log("[AsyncCoroutineRunner] Found GameObject but didn't have component");
68-
69-
if (Application.isPlaying)
70-
{
71-
Destroy(instanceGameObject);
72-
}
73-
else
74-
{
75-
DestroyImmediate(instanceGameObject);
76-
}
77-
}
63+
Debug.LogError($"GameObject {instance.gameObject.name} has an inactive AsyncCoroutineRunner attached and " +
64+
"there is no active AsyncCoroutineRunner in the scene. There must be an active AsyncCoroutineRunner attached to a GameObject at the root of the scene.");
65+
return instance;
7866
}
7967
}
8068

8169
if (instance == null)
8270
{
71+
Debug.LogWarning("There is no AsyncCoroutineRunner in the scene. Adding a GameObject with AsyncCoroutineRunner attached at the root of the scene.");
8372
instance = new GameObject("AsyncCoroutineRunner").AddComponent<AsyncCoroutineRunner>();
8473
}
8574

0 commit comments

Comments
 (0)