Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Teleportation with Netcode for GameObjects - Help in understanding

Discussion in 'Netcode for GameObjects' started by marzdh, Aug 20, 2023.

  1. marzdh


    Jun 3, 2013
    I'm having a lot of trouble understanding how teleportation works with Netcode for Gameobjects in VR.

    Currently 2 players are logging in (there will be more) . The first as a host and the second as a client.

    Teleportation works properly for the host when logged in first. When the client logs in, the teleportation stops working for the host and works only for the client.

    I have a NetworkPlayer script attached to each avatar (host and client) that spawns on the network which checks if the Teleportation Area has its own owner as a Teleportation Provider.

    The code mentioned below is part of the NetworkPlayer script and when executed on Update allows the host and client to teleport, but without it, only the client can teleport.

    Can someone help me understand if this is the right approach to making teleportation work? If not, what is?

    Code (CSharp):
    1. public void SetTA()
    2.     {
    3.         if (IsOwner)
    4.         {
    5.                 teleportationProvider = GetComponentInChildren<TeleportationProvider>();
    6.                 areas = FindObjectsOfType<TeleportationArea>();
    7.             foreach (TeleportationArea area in areas)
    8.             {
    9.                 area.teleportationProvider = teleportationProvider;
    10.             }
    11.         }
    12.     }

    The second issue I'm facing in VR is, when the client or host exits the experience, the experience just freezes for the other player who is still in the experience. How can I avoid this.