OnJoinedRoom() wont run

Options
Hi everyone

I'm having a problem: My OnJoinedRoom() wont run when In OnCreateRoom I load a scene. It's very strange because if I dont load the scene in OnCreateRoom() it instantiates the player in OnJoinedRoom() and the method runs perfectly. But when the scene is loaded in OnCreatedRoom() the method OnJoinedRoom() does not even runs ...

Heres the code:

void Awake() { // this makes sure we can use PhotonNetwork.LoadLevel() on the master client and all clients in the same room sync their level automatically PhotonNetwork.automaticallySyncScene = true; // the following line checks if this client was just created (and not yet online). if so, we connect if (PhotonNetwork.connectionStateDetailed == PeerState.PeerCreated) { // Connect to the photon master-server. We use the settings saved in PhotonServerSettings (a .asset file in this project) PhotonNetwork.ConnectUsingSettings("0.9"); } if (!PhotonNetwork.connected) { Debug.Log(PhotonNetwork.connectionStateDetailed.ToString()); } } void Start() { // Configuring Room Custom Properties roomProperties = new Hashtable(); } // (...) void OnReceivedRoomListUpdate() { roomsList = PhotonNetwork.GetRoomList(); } void OnJoinedLobby() { Debug.Log("OnJoinedLobby"); } void OnCreatedRoom() { Debug.Log("OnCreatedRoom"); Debug.Log("Created room: " + this.roomName); //Loads the scene PhotonNetwork.LoadLevel("Game"); } void OnJoinedRoom() { Debug.Log("OnJoinedRoom"); Debug.Log("Joined: " + this.roomName); //Spawn Player SpawnCharacter(); } void OnPhotonCreateRoomFailed() { // Show text with error Debug.LogWarning("Error: Can't create room, (room name maybe already used)"); }

Thanks in advance!

Comments

  • luxel
    Options
    When a new scene is loaded, current game objects are destroyed, so you won't be able to get OnJoinedRoom on current game object (which is owned by previous scene). :)
  • captalvez
    Options
    So the best way to instantiate the players, in this case, is use PhotonNetwork.Instantiate(...) in the Awake() method of a script owned by the scene that is loaded