Skip to content

Commit a7de17d

Browse files
committed
handling what to do when the camera has a parent
1 parent 17e74ce commit a7de17d

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

Assets/MixedRealityToolkit/_Core/Managers/MixedRealityManager.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using Microsoft.MixedReality.Toolkit.Core.Definitions;
@@ -364,8 +364,25 @@ public Transform MixedRealityPlayspace
364364
}
365365
else
366366
{
367-
mixedRealityPlayspace = new GameObject("MixedRealityPlayspace").transform;
368-
CameraCache.Main.transform.SetParent(mixedRealityPlayspace);
367+
string MixedRealityPlayspaceName = "MixedRealityPlayspace";
368+
if (CameraCache.Main.transform.parent == null)
369+
{
370+
mixedRealityPlayspace = new GameObject(MixedRealityPlayspaceName).transform;
371+
CameraCache.Main.transform.SetParent(mixedRealityPlayspace);
372+
}
373+
else
374+
{
375+
if (CameraCache.Main.transform.parent.name != MixedRealityPlayspaceName)
376+
{
377+
// Since the scene is set up with a different camera parent, its likely
378+
// that there's an expectation that that parent is going to be used for
379+
// something else. We print a warning to call out the fact that we're
380+
// co-opting this object for use with teleporting and such, since that
381+
// might cause conflicts with the parent's intended purpose.
382+
Debug.LogWarning("The Mixed Reality Manager expected the camera's parent to be named " + MixedRealityPlayspaceName + ". The existing parent will be renamed and used instead.");
383+
CameraCache.Main.transform.parent.name = MixedRealityPlayspaceName; // If we rename it, we make it clearer that why it's being teleported around at runtime.
384+
}
385+
}
369386

370387
// It's very important that the MixedRealityPlayspace align with the tracked space,
371388
// otherwise reality-locked things like playspace boundaries won't be aligned properly.

0 commit comments

Comments
 (0)