OnPlayerConnected not being called with PUN

Options
Hi,

In my game players connect to the server in a lobby/menu scene before starting in a level(new scene) together.
In that level(new scene) there's a gameobject with a GameManager script on it responsible for adding each player on a highscore board. I'm trying to start this proces with :
void OnPhotonPlayerConnected(PhotonPlayer pPlayer)
{
//Do stuff
Debug.Log("AreYouWorking?????????????????");

}

But the function is never called. Why?? Is it because the players are already connected and if so, how do I fix this?
The GameManager is in the new scene and inactive until the scene is started so wether or not players are already connected in another scene shouldn't matter should it?

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited May 2020
    Options
    Hi @petersenjmp,

    Thank you for choosing Photon!

    I think the other player enters the room when the scene is being loaded.
    PUN tries to trigger all implemented callbacks but since this one is still not available because the scene is not loaded yet.

    So try to make use of PhotonNetwork.isMessageQueueRunning.
    Set it to false before calling PhotonNetwork.LoadLevel to load the new scene and set it to true after that.

    Read more here and here (2nd link is about RPCs but same thing applies for all incoming Photon messages).
  • petersenjmp
    Options
    Thanks, i'll try it. but i did figure out a workaround that also worked using booleans and a foreach Photonplayer loop.