Skip to content

Commit 1c17f78

Browse files
Fixed input handler race condition if input system and teleport system not found before gameobjects wake up
1 parent 2631b94 commit 1c17f78

File tree

5 files changed

+68
-8
lines changed

5 files changed

+68
-8
lines changed

Assets/MixedRealityToolkit-SDK/Features/Input/GazeProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,10 @@ protected override void OnEnable()
268268
}
269269
}
270270

271-
protected virtual void Start()
271+
protected override void Start()
272272
{
273+
base.Start();
274+
273275
if (cursorPrefab != null)
274276
{
275277
var cursorObj = Instantiate(cursorPrefab, transform.parent);

Assets/MixedRealityToolkit-SDK/Features/Input/Handlers/SpeechInputHandler.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ public class SpeechInputHandler : BaseInputHandler, IMixedRealitySpeechHandler
3333

3434
#region MonoBehaviour Implementation
3535

36-
private void Start()
36+
protected override void Start()
3737
{
38+
base.Start();
39+
3840
if (persistentKeywords)
3941
{
4042
Debug.Assert(gameObject.transform.parent == null, "Persistent keyword GameObject must be at the root level of the scene hierarchy.");

Assets/MixedRealityToolkit-SDK/Features/Input/InputSystemGlobalListener.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,40 @@ public class InputSystemGlobalListener : MonoBehaviour
1515
private static IMixedRealityInputSystem inputSystem = null;
1616
protected static IMixedRealityInputSystem InputSystem => inputSystem ?? (inputSystem = MixedRealityManager.Instance.GetManager<IMixedRealityInputSystem>());
1717

18+
private bool lateInitialize = true;
19+
1820
protected virtual void OnEnable()
1921
{
20-
Debug.Assert(MixedRealityManager.IsInitialized, "No Mixed Reality Manager found in the scene. Be sure to run the Mixed Reality Configuration.");
21-
Debug.Assert(InputSystem != null, "No Input System found, Did you set it up in your configuration profile?");
22-
InputSystem.Register(gameObject);
22+
if (!MixedRealityManager.IsInitialized)
23+
{
24+
Debug.LogError("Missing Mixed Reality Manager!");
25+
return;
26+
}
27+
28+
if (InputSystem != null && !lateInitialize)
29+
{
30+
InputSystem.Register(gameObject);
31+
}
32+
}
33+
34+
protected virtual void Start()
35+
{
36+
if (lateInitialize)
37+
{
38+
if (InputSystem == null)
39+
{
40+
Debug.LogError("Unable to find Input System!");
41+
return;
42+
}
43+
44+
lateInitialize = false;
45+
InputSystem.Register(gameObject);
46+
}
2347
}
2448

2549
protected virtual void OnDisable()
2650
{
27-
InputSystem.Unregister(gameObject);
51+
InputSystem?.Unregister(gameObject);
2852
}
2953
}
3054
}

Assets/MixedRealityToolkit-SDK/Features/UX/Scripts/Cursors/BaseCursor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ protected virtual void UpdateCursorTransform()
316316
{
317317
Debug.LogError($"{name}: Unable to get focus details for {pointer.GetType().Name}!");
318318
}
319+
else
320+
{
321+
Debug.LogWarning($"{pointer.GetType().Name} not registered!");
322+
}
319323

320324
return;
321325
}

Assets/MixedRealityToolkit-SDK/Features/UX/Scripts/Pointers/BaseControllerPointer.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public abstract class BaseControllerPointer : ControllerPoseSynchronizer, IMixed
6161

6262
protected bool IsTeleportRequestActive = false;
6363

64+
private bool lateRegisterTeleport = false;
65+
6466
/// <summary>
6567
/// The forward direction of the targeting ray
6668
/// </summary>
@@ -116,7 +118,33 @@ protected override void OnEnable()
116118
base.OnEnable();
117119
SetCursor();
118120
BaseCursor?.SetVisibility(true);
119-
TeleportSystem?.Register(gameObject);
121+
122+
if (TeleportSystem == null)
123+
{
124+
lateRegisterTeleport = true;
125+
}
126+
else if (!lateRegisterTeleport)
127+
{
128+
TeleportSystem.Register(gameObject);
129+
}
130+
}
131+
132+
protected override void Start()
133+
{
134+
base.Start();
135+
136+
if (lateRegisterTeleport)
137+
{
138+
if (TeleportSystem == null)
139+
{
140+
Debug.LogError("Failed to find the Teleport System!");
141+
}
142+
else
143+
{
144+
lateRegisterTeleport = false;
145+
TeleportSystem.Register(gameObject);
146+
}
147+
}
120148
}
121149

122150
protected override void OnDisable()
@@ -171,7 +199,7 @@ public string PointerName
171199
}
172200

173201
/// <inheritdoc />
174-
public IMixedRealityInputSource InputSourceParent { get; private set; }
202+
public IMixedRealityInputSource InputSourceParent { get; protected set; }
175203

176204
/// <inheritdoc />
177205
public IMixedRealityCursor BaseCursor { get; set; }

0 commit comments

Comments
 (0)