Skip to content

Commit bc2287e

Browse files
authored
Merge pull request #3553 from StephenHodgson/v2-async-fixes
Fixed an issue with creating multiple async runners.
2 parents cc5f781 + 1c3e99b commit bc2287e

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

Assets/MixedRealityToolkit/Utilities/Async/Internal/AsyncCoroutineRunner.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,36 @@ internal static AsyncCoroutineRunner Instance
4848
if (instance == null)
4949
{
5050
var instanceGameObject = GameObject.Find("AsyncCoroutineRunner");
51+
5152
if (instanceGameObject != null)
5253
{
5354
instance = instanceGameObject.GetComponent<AsyncCoroutineRunner>();
55+
5456
if (instance == null)
5557
{
5658
Debug.Log("[AsyncCoroutineRunner] Found GameObject but didn't have component");
57-
Destroy(instanceGameObject);
59+
60+
if (Application.isPlaying)
61+
{
62+
Destroy(instanceGameObject);
63+
}
64+
else
65+
{
66+
DestroyImmediate(instanceGameObject);
67+
}
5868
}
5969
}
70+
}
6071

72+
if (instance == null)
73+
{
6174
instance = new GameObject("AsyncCoroutineRunner").AddComponent<AsyncCoroutineRunner>();
62-
instance.gameObject.hideFlags = HideFlags.HideInHierarchy;
75+
}
76+
77+
instance.gameObject.hideFlags = HideFlags.None;
6378
#if !UNITY_EDITOR
64-
DontDestroyOnLoad(instance);
79+
DontDestroyOnLoad(instance);
6580
#endif
66-
}
6781

6882
return instance;
6983
}

0 commit comments

Comments
 (0)