The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

State: ConnectingToMasterserver on return to menu

KamiCompute
2020-02-29 11:31:12

Hi there,
I'm using Photon 2.16 / lib 4.1.2.19.

My app has a single and multiplayer scene.
When it starts, it connects to the master server using PhotonNetwork.ConnectUsingSettings().
When connected, I can load a lobby and connect to a random room. If I cancel and call leaveroom, I get back in the main menu, still connected and ready to join a new random room.

However,
When I actually start a game (either single or multiplayer) and leave that game to go back to the menu (loadscene menu via Unity scenemanagement), I am no longer able to e.g. create / join a random room. When trying to connect using PhotonNetwork.ConnectUsingSettings(), it hangs on 'ConnectingToMasterserver', and gives this error when trying to make a match:

JoinRandomRoom failed. Client is on MasterServer (must be Master Server for matchmaking) but not ready for operations (State: ConnectingToMasterserver). Wait for callback: OnJoinedLobby or OnConnectedToMaster.
Weird thing is, according to PhotonNetwork.IsConnected, we are (true).

It never gets past this point.
When I stop the app and restart it, it connects fine to the MasterServer and all is well again, until I actually load a game and return to the menu.

I've tried calling .Disconnect() when loading a single player game, and on reload of the menu scene, according to PhotonNetwork.IsConnected, we are not (as expected, false). But when calling PhotonNetwork.ConnectUsingSettings(), again it hangs on the State: ConnectingToMasterserver. Also, I tried to first do a PhotonNetwork.Reconnect(), and it connects fine according to the state. But alas, again hanging on ConnectingToMasterserver.

What could be the issue here? How can I troubleshoot this?

Thanks up front for your help!

Kind regards,
Kami.

Comments

S_Oliver
2020-02-29 13:27:31

Hi I got this behaviour too. The issue is that all stuff connecting, joining room is in one scene. https://github.com/SradnickDev/GravityCombat/blob/master/Source/Assets/Scripts/UI/Login/LoginModel.cs

I used an switch case to determine in what state the client was and forces photon to connect or do what ever is needed.

KamiCompute
2020-03-02 12:14:09

Hi Oliver,

Thanks for your feedback. I see that you use the state to determine what action to take. However, my issue is that according to PUN, I am "Connected and Ready" (PhotonNetwork.IsConnectedAndReady == true).

But in reality, I'm not after returning to the menu, since I cannot e.g. join a random room:
(JoinRandomRoom failed. Client is on MasterServer (must be Master Server for matchmaking) but not ready for operations (State: Joining). Wait for callback: OnJoinedLobby or OnConnectedToMaster.).

I've tried calling various actions depending on the callback (reconnect, disconnect / connect, connectusingsettings etc) but they always claim I am connected on that part.

S_Oliver
2020-03-02 13:58:04

Did you simply tried using https://doc-api.photonengine.com/en/dotnet/current/class_photon_1_1_realtime_1_1_support_logger.html#a2b53fdd4655db3ce620a1b7cef4fa734
or waiting for OnConnectedToMaster() so you can call JoinRandomRoom ?

Would you share your code so i can take a look ?

KamiCompute
2020-03-10 14:37:07

Hi Olivier,

Sorry for my late reply.
I have the additional logging enabled, but doesn't reveal the issue.

The flow:

  • app starts, ConnectUsingSettings is called;
  • I get connected succesfully, and OnConnectedToMaster is returned succesfully;
  • I can join a room without problems, and the game scene is loaded;
  • when leaving the game, I return to the main menu. Since the script calling ConnectUsingSettings is linked here, it triggers;
  • this time, I am not connected succesfully, instead it hangs on ConnectingToMasterserver;

It never gets passed this point, and ConnectedOnMaster is never triggered. The state remains: State: ConnectingToMasterserver.
I've tried running ConnectUsingSettings again, no change. I've tried calling Disconnect, which seems to do some calls, but then the state hangs on: State: Disconnecting.

What I would expect to happen after returning to the main menu, is that ConnectUsingSettings makes a new connection to the Photon MasterServer, like when you start the app.
I assume it never disconnected when returning to the menu, so I tried using PhotonNetwork.IsConnectedAndReady logic to determine first if we are connected, and if so, do nothing. If it is disconnected, try reconnect and if that fails, call ConnectUsingSettings.
The problem is that when returning to the main menu from the game, PhotonNetwork.IsConnectedAndReady == true, but I can't e.g. JoinRandomRoom anymore:

(JoinRandomRoom failed. Client is on MasterServer (must be Master Server for matchmaking) but not ready for operations (State: Joining). Wait for callback: OnJoinedLobby or OnConnectedToMaster.).

Are my expectations wrong? I'm happy to share code, but I would first want to understand if my logic is incorrect.

Thanks again!

KamiCompute
2020-03-16 13:45:33

bump.

Tobias
2020-03-16 16:08:01

@S_Oliver, maybe you can help when you are around?

Tobias
2020-03-16 16:12:15

@KamiCompute:
When you leave a room, OnConnectedToMaster() gets called again, as PUN (or more precisely the Realtime API) returns you from the Game Server to the Master Server. You should keep your script from calling ConnectUsingSettings. It should (in theory) just return false and that's it.

Could you share a minimal repro project? Empty scenes, just the needed scripts?
You could mail that to [email protected]

KamiCompute
2020-03-18 13:06:03

Hi Tobias,
When leaving a room, it works. The first time I start the app, the player can click on Multiplayer, which brings them to a different scene, a lobby. This is done through JoinRandomRoom. I can join / leave this room without any issues, I stay connected. But when I load my gamescene, either via the lobby -> multiplayer scene, or when loading the single player game (so I never call joinrandomroom), when leaving that scene and returning to the main menu, I am no longer connected to the master server.

@Tobias wrote: »

@KamiCompute:
You should keep your script from calling ConnectUsingSettings.

I do this, but to make it more simplified, I'm not calling connect in Start, but via buttons.

When I start and press connect, I'm connected and can call JoinRandomRoom, which loads a new scene (lobby).
When I load my game scene and go back to the menu, and I call JoinRandomRoom, it fails.
When I manually call OnConnectedToMaster(), I get 2 outputs:

We're now connected to the eu server! (OnConnectedMasterCallback)
Connection Details: We are connected and ready! (OnConnectedMasterCallback)

But still, when trying to JoinRandomRoom, it fails:
JoinRandomRoom failed. Client is on MasterServer (must be Master Server for matchmaking) but not ready for operations (State: Joining). Wait for callback: OnJoinedLobby or OnConnectedToMaster.
UnityEngine.Debug:LogError(Object)

@Tobias wrote: »

@KamiCompute:
Could you share a minimal repro project?

I'll see that I create it and send it.

Thanks again!

S_Oliver
2020-03-19 15:36:42

Hi sry for the late reply. If you still encounter the issue , hit me on discord Daegit#4499 .

Would be nice if you could share your project on discord, this makes stuff easier.

KamiCompute
2020-12-02 13:00:16

Solved. Issue: I'm an idjit.

So... what happens...
Once I'm in a 'level' scene, when I open the menu, I set the TimeScale to 0 (so things 'freeze', since Unity doesn't really have a 'pause' function).
Hence, when I go back to the menu, the timescale is still at 0... I never resetted it to 1.

....
....

Quickfix for now: Time.timeScale = 1.0f at Menu script start.
Long term fix: going to rethink my 'pause' methods.

Anyway, this explains a lot... I never realized that Photon takes into account time scales. Makes total sense that it does.

JohnTube
2020-12-03 11:28:39

Hi @KamiCompute,

Thank you for choosing Photon!

I never realized that Photon takes into account time scales.

Take a look here.

Back to top