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

Third Party How do I fix this error

Discussion in 'Multiplayer' started by TrexMatrix, Aug 29, 2023.

  1. TrexMatrix

    TrexMatrix

    Joined:
    Aug 8, 2023
    Posts:
    41
    I'm new to making multiplayer games and I'm following this tutorial


    Everything going fine until at the very end I got this error:
    Can not Instantiate before the client joined/created a room. State: Joining
    UnityEngine.Debug:LogError (object)

    I don't know what it is or how to fix it. This is also my script:
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using Photon.Pun;
    6.  
    7. public class RoomManager : MonoBehaviourPunCallbacks
    8. {
    9.     public GameObject player;
    10.  
    11.     [Space]
    12.     public Transform spawnPoint;
    13.  
    14.  
    15.     // Start is called before the first frame update
    16.     void Start()
    17.     {
    18.         Debug.Log("Connecting...");
    19.  
    20.         PhotonNetwork.ConnectUsingSettings();
    21.     }
    22.  
    23.  
    24.     public override void OnConnectedToMaster()
    25.     {
    26.         base.OnConnectedToMaster();
    27.  
    28.         Debug.Log("Connected to Server");
    29.  
    30.         PhotonNetwork.JoinLobby();
    31.     }
    32.  
    33.  
    34.     public override void OnJoinedLobby()
    35.     {
    36.         base.OnJoinedLobby();
    37.  
    38.         PhotonNetwork.JoinOrCreateRoom("test", null, null);
    39.  
    40.         Debug.Log("We're connected and in a room now");
    41.  
    42.         GameObject _player = PhotonNetwork.Instantiate(player.name, spawnPoint.position, Quaternion.identity);
    43.     }
    44. }
    45.