Search Unity

Question Instantiated XROrigin breaks Teleport capability

Discussion in 'XR Interaction Toolkit and Input' started by Gamerprime99, Sep 6, 2022.

  1. Gamerprime99

    Gamerprime99

    Joined:
    Oct 13, 2021
    Posts:
    2
    Hi! I am currently developing a networked VR experience using Photon. I have a prefab of a XROrigin that I am spawning into the scene upon a player joining the Photon room, however, I am encountering an issue where teleport no longer works for the instantiated XROrigin, but will work when placing the prefab into the scene normally.

    My experience is utilizing the unity XR Interaction Toolkit and all appropriate surfaces have the teleport area component. I am currently using Unity version 2020.3.35f1. I have attached a screenshot of my XROrigin prefab's inspector.

    Any and all help would be greatly appreciated. Thank you!
     

    Attached Files:

  2. Gamerprime99

    Gamerprime99

    Joined:
    Oct 13, 2021
    Posts:
    2
    Just to add some additional information here, if I start the experience and remove the teleport area components from the floor and add them again, teleport will work again. Is there anyway around this issue?
     
  3. amydigiov_Unity

    amydigiov_Unity

    Unity Technologies

    Joined:
    May 24, 2016
    Posts:
    16
    Hi @Gamerprime99, I believe the problem is that the Teleport Area components do not have a reference to the Teleportation Provider. Removing and adding them again at runtime fixes the issue because the Teleport Area attempts to find a Teleportation Provider on Awake.

    There are a few ways you could fix this with a custom script. You could keep the Teleport Area components disabled and only enable them at runtime after the XROrigin has been instantiated. An alternative is that you could go through each
    BaseTeleportationInteractable
    and set the property
    teleportationProvider
    to the
    TeleportationProvider
    instance once it is available.
     
  4. mariamdh

    mariamdh

    Joined:
    Aug 24, 2023
    Posts:
    2
    @amydigiov_Unity I am facing a similar problem with Network Prefabs for a multiplayer game. The prefab I am spawning is an XROrigin. I'm using the NetworkManager (Netcode) to start the host.
    I am adding the Teleportation Area component at runtime to the floor (the floor has a mesh collider) -

    Code (CSharp):
    1. public class TeleportationPlane : MonoBehaviour
    2. {
    3.     [SerializeField] GameObject reticlePrefab;
    4.     TeleportationArea area;
    5.  
    6.     private void Start()
    7.     {
    8.         area = gameObject.AddComponent<TeleportationArea>();
    9.         area.customReticle = reticlePrefab;
    10.     }
    11. }
    On the spawned player, in the update function I'm setting the teleportation provider to the teleportation area.

    Code (CSharp):
    1.  private void Awake()
    2.     {
    3.         teleportationProvider = GetComponentInChildren<TeleportationProvider>();
    4.     }
    5.  
    6. private void Update()
    7.     {
    8.         SetTA();
    9.     }
    10.  
    11.     public void SetTA()
    12.     {
    13.         if (IsOwner)
    14.         {
    15.             areas = FindObjectsOfType<TeleportationArea>();
    16.             //Debug.Log(teleportationProvider);
    17.             //Debug.Log($"Teleportation Area Count {areas.Length}");
    18.             foreach (TeleportationArea area in areas)
    19.             {
    20.                 area.teleportationProvider = teleportationProvider;
    21.             }
    22.         }
    Yet when trying to teleport, the XR Interactor line stays red and teleportation just doesn't work. Any idea why this could be happening?
     
    Last edited: Aug 28, 2023
  5. LizhengheChen

    LizhengheChen

    Joined:
    Oct 14, 2021
    Posts:
    1
    Yes, these solutions work on my project!!