Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug XR player freezes when another leaves the room.

Discussion in 'XR Interaction Toolkit and Input' started by unity_rLrstvXScQEvow, Oct 29, 2022.

  1. unity_rLrstvXScQEvow

    unity_rLrstvXScQEvow

    Joined:
    Mar 4, 2019
    Posts:
    28
    I'm working on a XR multiplayer (PUN2) project from my studies and can't figure out why my player freezes when someone else leaves the room.

    Here is the scenario:
    P1 enters the room. P2 joins. When one of the two players leaves the room, the remaining players freeze. Means: They can't move their hands anymore and they can't walk. The head/camera works means they can look around. If now another player enters the room everything is back to normal.

    The code below is the logic I use within the rooms. Line 20 has not changed anything. The player disappears when he leaves the room regardless of this line.

    Code (CSharp):
    1. public class GameManager : MonoBehaviourPunCallbacks
    2. {
    3.     [SerializeField] private GameObject networkPlayerPrefab;
    4.     private GameObject spawnedPlayer; // local Player
    5.  
    6.     public void LeaveRoom()
    7.     {
    8.         PhotonNetwork.LeaveRoom();
    9.     }
    10.  
    11.     #region Photon
    12.     public override void OnJoinedRoom()
    13.     {
    14.         spawnedPlayer = PhotonNetwork.Instantiate(networkPlayerPrefab.name, transform.position, Quaternion.identity);
    15.     }
    16.  
    17.     public override void OnLeftRoom()
    18.     {
    19.         base.OnLeftRoom();
    20.         //PhotonNetwork.Destroy(spawnedPlayer);
    21.         SceneManager.LoadScene(0);
    22.     }
    23.  
    24.     public override void OnPlayerEnteredRoom(Player newPlayer)
    25.     {
    26.         base.OnPlayerEnteredRoom(newPlayer);
    27.         Debug.LogFormat("Beigetreten {0}", newPlayer.NickName); // Sieht man nicht wenn man selber der Spieler ist
    28.     }
    29.  
    30.     public override void OnPlayerLeftRoom(Player otherPlayer)
    31.     {
    32.         base.OnPlayerLeftRoom(otherPlayer);
    33.         Debug.LogFormat("Verlassen: {0}", otherPlayer.NickName); // Sieht man nicht wenn man selber der Spieler ist
    34.     }
    35.     #endregion
    Has anyone had similar experiences or any idea what the problem might be? I think it could be specifically the XR Toolkit (2.0) scripts.
     
  2. unity_rLrstvXScQEvow

    unity_rLrstvXScQEvow

    Joined:
    Mar 4, 2019
    Posts:
    28
    Update: It has nothing to do with Photon. The same thing happens when you create a second XR Origin player offline and destroy it.
     
  3. unity_rLrstvXScQEvow

    unity_rLrstvXScQEvow

    Joined:
    Mar 4, 2019
    Posts:
    28
    The problem:
    As soon as more than one XR Origin with an Input Action Manager is in the scene and one of them is destroyed, all inputs seem to be disabled.

    Solution:
    When destroying a player, I now searched for all Input Action Manager scripts in the scene and called "EnableInput()" once.
     
    s5907610 likes this.
  4. s5907610

    s5907610

    Joined:
    Oct 11, 2021
    Posts:
    2
    Thank you for the helpful tips!