Unity-Technologies / XR-Interaction-Toolkit-Examples

This repository contains various examples to use with the XR Interaction Toolkit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Teleportation Area does not find Teleportation Provider when in another scene [Fix Found]

LeaT113 opened this issue · comments

Scene 1 has the XR Rig and all the XR scripts including Teleportation Provider.
Scene 2 has a Teleportation Area. Scene 2 is active.

When hitting play in Editor, the Teleportation Area correctly acquires an XR Interaction Manager reference (from Scene 1), but does not find the Teleportation Provider reference (that also resides in Scene 1). This results in a non-functional TP Area. When put into Scene 1, it does find a Teleportation Provider reference successfully.

Analysis

It seems this is caused by using the Awake method instead of the Start method. I created a script that uses FindObjectOfType<TeleportationProvider>(), same as the internal XRI logic, and it was unable to find the reference in the Awake method. However, when I put the same method call into the Start method, it found the reference.

As to why the XR Interaction Manager is found, but the Teleportation Provider isn't - I believe that is because when I traced how the Interaction Manager reference is acquired, I found it is in the XRBaseInteractable class, there is an #if UNITY_EDITOR that uses an EditorComponentLocatorUtility.FindSceneComponentOfType<T>(Scene scene) that seems to have the ability to find the reference in other scenes.

Possible fixes:

  • use the EditorComponentLocatorUtility for the Teleportation Provider reference too
  • use Start instead of Awake for sourcing the Teleportation Provider reference. I am not sure the first solution would work, as it would only affect the Editor and I'm unsure if this issue is present in Builds, I only tested the Editor behavior.

I came across this issue in slightly different situation: because of the business logic requirements my whole XRRig and all that is created after the scene has started.

I added a script FixTeleportAreas to my XRRig prefab that uses FindObjectsOfType<BaseTeleportationInteractable>() to find all teleportation areas and anchors and fills in the correct interactionManager and teleportationProvider.

Not pretty but it does the job.