Instantiated XROrigin breaks Teleport capability

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!

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?

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.

5 Likes

@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) -

public class TeleportationPlane : MonoBehaviour
{
    [SerializeField] GameObject reticlePrefab;
    TeleportationArea area;

    private void Start()
    {
        area = gameObject.AddComponent<TeleportationArea>();
        area.customReticle = reticlePrefab;
    }
}

On the spawned player, in the update function I’m setting the teleportation provider to the teleportation area.

 private void Awake()
    {
        teleportationProvider = GetComponentInChildren<TeleportationProvider>();
    }

private void Update()
    {
        SetTA();
    }

    public void SetTA()
    {
        if (IsOwner)
        {
            areas = FindObjectsOfType<TeleportationArea>();
            //Debug.Log(teleportationProvider);
            //Debug.Log($"Teleportation Area Count {areas.Length}");
            foreach (TeleportationArea area in areas)
            {
                area.teleportationProvider = teleportationProvider;
            }
        }

Yet when trying to teleport, the XR Interactor line stays red and teleportation just doesn’t work. Any idea why this could be happening?

Yes, these solutions work on my project!!

Hi. Has anyone solved this problem? I’ve tried as suggested but it does not seem to be working. I can see that the teleportation providers fill in in the inspector but still teleportation does not work.

// Link teleportation surfaces
TeleportationProvider teleportationProvider = GetComponentInChildren<TeleportationProvider>();
BaseTeleportationInteractable[] teleportationInteractables = FindObjectsOfType<BaseTeleportationInteractable>();
Debug.Log($"Registering {teleportationInteractables.Length} teleportation interactables.");
foreach (BaseTeleportationInteractable teleportationInteractable in teleportationInteractables)
{
    teleportationInteractable.teleportationProvider = teleportationProvider;
}

Figured it out. Being new to multiplayer development, I didn’t realize you are meant to create “avatars” for your player controllers. So, in your scene have your player prefab already placed so the local client can control that. Then, you want to instantiate an “avatar” prefab at runtime to represent just your player model across the network. This avatar should mimic the transform of your local client. This way all of the teleportation nonsense is filled in at start, and you don’t have to worry about disabling scripts on your player controller.

2 Likes