Skip to content

Commit d61260e

Browse files
wait until we have a valid teleport system
1 parent 7c960a6 commit d61260e

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Microsoft.MixedReality.Toolkit.Core.Managers;
1414
using Microsoft.MixedReality.Toolkit.SDK.Input.Handlers;
1515
using System.Collections;
16+
using Microsoft.MixedReality.Toolkit.Core.Utilities.Async;
1617
using UnityEngine;
1718

1819
namespace Microsoft.MixedReality.Toolkit.SDK.UX.Pointers
@@ -61,7 +62,7 @@ public abstract class BaseControllerPointer : ControllerPoseSynchronizer, IMixed
6162

6263
protected bool IsTeleportRequestActive = false;
6364

64-
private bool lateRegisterTeleport = false;
65+
private bool lateRegisterTeleport = true;
6566

6667
/// <summary>
6768
/// The forward direction of the targeting ray
@@ -119,31 +120,21 @@ protected override void OnEnable()
119120
SetCursor();
120121
BaseCursor?.SetVisibility(true);
121122

122-
if (TeleportSystem == null)
123-
{
124-
lateRegisterTeleport = true;
125-
}
126-
else if (!lateRegisterTeleport)
123+
if (MixedRealityManager.IsInitialized && TeleportSystem != null && !lateRegisterTeleport)
127124
{
128125
TeleportSystem.Register(gameObject);
129126
}
130127
}
131128

132-
protected override void Start()
129+
protected override async void Start()
133130
{
134131
base.Start();
135132

136133
if (lateRegisterTeleport)
137134
{
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-
}
135+
await new WaitUntil(() => TeleportSystem != null);
136+
lateRegisterTeleport = false;
137+
TeleportSystem.Register(gameObject);
147138
}
148139
}
149140

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public override void OnPositionInputChanged(InputEventData<Vector2> eventData)
290290
{
291291
teleportEnabled = true;
292292

293-
TeleportSystem.RaiseTeleportRequest(this, TeleportHotSpot);
293+
TeleportSystem?.RaiseTeleportRequest(this, TeleportHotSpot);
294294
}
295295
else if (canMove)
296296
{
@@ -356,15 +356,15 @@ public override void OnPositionInputChanged(InputEventData<Vector2> eventData)
356356
if (TeleportSurfaceResult == TeleportSurfaceResult.Valid ||
357357
TeleportSurfaceResult == TeleportSurfaceResult.HotSpot)
358358
{
359-
TeleportSystem.RaiseTeleportStarted(this, TeleportHotSpot);
359+
TeleportSystem?.RaiseTeleportStarted(this, TeleportHotSpot);
360360
}
361361
}
362362

363363
if (teleportEnabled)
364364
{
365365
canTeleport = false;
366366
teleportEnabled = false;
367-
TeleportSystem.RaiseTeleportCanceled(this, TeleportHotSpot);
367+
TeleportSystem?.RaiseTeleportCanceled(this, TeleportHotSpot);
368368
}
369369
}
370370

0 commit comments

Comments
 (0)