Skip to content

Commit fa2fea5

Browse files
committed
Use SpatialMappingManager instance instead of FindObjectByType
1 parent 36a4380 commit fa2fea5

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Assets/HoloToolkit/Utilities/Scripts/WorldAnchorManager.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,27 +141,31 @@ public void RemoveAnchor(GameObject gameObjectToUnanchor)
141141
/// </summary>
142142
public void RemoveAllAnchors()
143143
{
144+
SpatialMappingManager spatialMappingManager = SpatialMappingManager.Instance;
145+
144146
// This case is unexpected, but just in case.
145147
if (AnchorStore == null)
146148
{
147149
Debug.LogError("remove all anchors called before anchor store is ready.");
148150
}
149151

150152
WorldAnchor[] anchors = FindObjectsOfType<WorldAnchor>();
151-
SpatialMappingManager spatialMappingManager = FindObjectOfType<SpatialMappingManager>();
152153

153154
if (anchors != null)
154155
{
155156
foreach (WorldAnchor anchor in anchors)
156157
{
157-
//Don't remove SpatialMapping anchors
158-
if (anchor.gameObject.transform.parent.gameObject != spatialMappingManager.gameObject)
158+
// Don't remove SpatialMapping anchors if exists
159+
if (spatialMappingManager == null ||
160+
anchor.gameObject.transform.parent.gameObject != spatialMappingManager.gameObject)
161+
{
159162
anchorOperations.Enqueue(new Unity.WorldAnchorManager.AnchorAttachmentInfo()
160163
{
161164
AnchorName = anchor.name,
162165
GameObjectToAnchor = anchor.gameObject,
163166
Operation = AnchorOperation.Delete
164167
});
168+
}
165169
}
166170
}
167171
}

0 commit comments

Comments
 (0)