Connecting to Master Server works in build but not editor.

The whole answer can be found below.

Please note: 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! And we offer you support through 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.

Connecting to Master Server works in build but not editor.

Jakeco19
2018-08-08 13:36:26

Iv experience this issue several time once in unity 2018.1 and 2018.2.

the editor will work for a period of time then after maybe 2 - 3 hours working, it no longer connects to the master.

I then build the game and the built version works and is able to connect. any ideas or suggestions would be greatly appreciated.

Have tried.

  • Fresh install
  • Host
  • New Project
  • Different Versions of unity
  • restarting router/Modem
  • Restarting pc
  • Restarting Unity

Comments

Jakeco19
2018-08-08 13:41:09

//Connect To the master Server  
    public void connectToPhoton()  
    {  
        PhotonNetwork.ConnectUsingSettings(versionName);  
        currentNetworkStatus = "Connecting";  
        Debug.Log("Connecting To photon.....");  
    }

    //Was able to connect to the master Server  
    private void OnConnectedToMaster()  
    {  
        PhotonNetwork.JoinLobby(TypedLobby.Default);  
        currentNetworkStatus = "Connected";  
        Debug.Log("Connected To the master");  
    }

    //Was Disconnected from the master server  
    private void OnDisconnectedFromPhoton()  
    {  
        currentNetworkStatus = "Disconnected";  
        Debug.Log("Disconnected from Photon services");  
    }

    public void joinRoomScene()  
    {  
        PhotonNetwork.LoadLevel("PlayScene");  
    }

    //Joined lobby  
    private void OnJoinedLobby()  
    {  
        Debug.Log("Joined Lobby");  
    }

This currently how I connect to the master.

JohnTube
2018-08-08 14:27:48

Hi @Jakeco19,

Thank you for choosing Photon!

What "Scripting Runtime Version" are you using? (Edit -> Project Settings -> Player) under "Configuration"
It should be "Stable (.NET 3.5 Equivalent)".
PUN does not support 4.6 yet (see this forum post).

If you implement these two callbacks which one is triggered and what disconnect cause do you get?

void OnConnectionFail(DisconnectCause cause)

void OnFailedToConnectToPhoton(DisconnectCause cause)

Jakeco19
2018-08-08 14:36:54

Hi @JohnTube

The Callbacks are never called and yes im using .Net 3.5;

JohnTube
2018-08-08 16:21:12

This is tricky to reproduce.
I think it may be a Unity bug.

it no longer connects to the master.
Could you explain this further? What happens? Any logs?

Jakeco19
2018-08-08 16:29:21

there is no real way to tell whats going on, other than the basic UI and Debugging that I have done.

im not to sure how to explain it but it was working at one stage, then stopped working without any edits done to the game.

using the Demos given, it gets stuck on connecting to name server, and will not proceed past that, but when I build the game it works perfectly fine.

Jakeco19
2018-08-09 03:18:44

Really need a solution this as it makes it impossible to even use Photon. seeing as i cant use the editor.

[Deleted User]
2018-08-09 09:46:29

the editor will work for a period of time then after maybe 2 - 3 hours working, it no longer connects to the master.

Just to make sure I understood this correctly: neither restarting the Unity Editor nor the PC solves the issue?

Jakeco19
2018-08-09 11:29:38

@Christian_Simon Hi,

yes, you are correct. neither of those worked.

[Deleted User]
2018-08-09 13:14:09

Odd, never heard of something similar before.

How do you try to connect to Photon? Do you use Best Region feature or a certain Cloud Region? Which Connection Protocol do you use? If this occurs next time, please try to change at least one of the settings and see what happens afterwards.

When you are already taking a look at the PhotonServerSettings, you can also try to set Pun Logging to Full and Network Logging to ALL and see, if this might give you any further hint about the problem.

Jakeco19
2018-08-10 02:58:37

iv tried all the options for trying to connect, none have worked. Have tried both UDP and TCP.

have tried but once again never gets an error sent instead just sits on connecting to name server.

Jakeco19
2018-08-10 17:32:52

Fixed the Issue, simply the fix is if you're using auto Sync on a folder that contains your project files turn that off or move the project files and it fixes it.

JohnTube
2018-08-13 14:39:49

Hi @Jakeco19,

Thank you for the heads up.
I'm glad you finally solved this mystery.

I'm however not sure how to suggest the fix to other customers who might have the same issue.
Could you please elaborate and share more details.
That would be very much appreciated.

Jakeco19
2018-08-18 11:45:06

@JohnTube

Here is how it was happening,

I had the folder of my unity project in my OneDrive folder, which auto-syncs. This would be any case for google drive, megasync, Dropbox and pretty much any service that has a folder on your computer that syncs to the cloud.

I moved that to local storage folder, say the desktop or C drive, and that fixed the issue.

The best fix that i could say is to move the folder to somewhere that doesn't auto sync to a cloud service.

Sufyan
2018-11-04 06:24:51

@JohnTube So Any Solution to this?

Sufyan
2018-11-04 06:25:15

@Jakeco19 Which folder?

mauri_up
2018-11-07 01:30:40

For anyone who comes across this issue, I managed to fix it after looking around the PhotonServerSettings file.
I noticed the current region would be set during offline mode but didn't get reset when calling PhotonNetwork.Connect() in online mode.
Try calling PhotonNetwork.Disconnect if you're switching from offline to online mode:

if (PhotonNetwork.offlineMode)  
{  
     PhotonNetwork.Disconnect ();  
}  
PhotonNetwork.offlineMode = false;  
PhotonNetwork.ConnectUsingSettings ("game version");  

Sufyan
2018-11-07 13:29:18

for new comers facing this, shoud try @mauri_up solution, other than that clearing unity temp folder from windows temp folder and clearing RPC"s from PhotonSettings and restricting reigon might help.

Turkoz14
2018-12-13 20:56:29

Hi im facing the same problem i following some tutorials and cant joined a room because the OnJoinedToMaster() callback doest work.

	public void ConnectToPhoton()  
	{  
		PhotonNetwork.ConnectUsingSettings();  
		  
		Debug.Log("Connecting to photon...");  
	}

	private void OnConnectedToMaster()  
	{  
		PhotonNetwork.JoinLobby(TypedLobby.Default);  
		  
		Debug.Log("We are connecte to master");  
	}

	private void OnJoinedLobby()  
	{  
		string notification = "On Joined Lobby";  
		  
		connectPanel.SetActive(false);

		statusText.text = notification;  
		statusText.color = Color.green;

		Debug.Log(notification);  
	}

	private void OnDisconnectedFromPhoton()  
	{  
		string notification = "Disconnected from photon services";

		if(connectPanel.activeSelf)  
			connectPanel.SetActive(false);

		statusText.tag = notification;  
		statusText.color = Color.red;  
		

		Debug.Log(notification);  
	}

Terralux
2019-01-20 09:34:42

Hey all, I ran into the same problem yesterday and here's what I tried in order to fix it:
I tried to restart Unity - Didn't solve the issue
I tried to restart my PC - Didn't solve the issue
I tried to move my Unity project - Didn't solve the issue
I tried to clean my windows temporary files - Didn't solve the issue
I tried to use the proposed by @mauri_up - Didn't solve the issue

The actual solution for me was to find the PhotonServerSettings asset in my Unity assets folder and click "Clear RPCs" then "Refresh RPCs" then I clicked the "Reset" button under Best Region Preference

That solved it in my case, hope this helps someone out there!

mm117
2019-02-12 05:51:07

Hi, I also ran into this problem. (Photon v2)

I tried all the steps stated above, and setting the region whitelist was the fix for me.

Once I set a region I was able to connect to the editor again.

Hope that helps.

BlAcK_BlAcKiTo
2019-03-14 19:52:03

Was facing this issue second time, last time had to revert by Collab few hours work, it was baaad, this time, Terralux Solution Worked for me! Problem was: standalones were going without problem, but unity editor wouldnt connect at all, it was debbuging it it connecting to master server, and could create room and play, but nooone seen him and he didnt see anyone. Bad situation. Luckily reseting RPC and Clearing and Refreshing RPCs in PhotonServerSettings helped!

AnilBayburt
2020-04-26 18:15:37

I was having the same issue, the build versions were connecting on same room successfully, but editor couldn't join. Trying everything above couldn't fix it.
Finally with some debug information I found out thet editor and build versions were connecting to servers from different regions.
Fixing the region setting on photon server settings fixed it for me...

jackmca
2022-08-17 05:02:15

I encountered this problem after I pressed 'Clear RPCs' and then 'Refresh RPCs' in the PhotonServerSettings, I fixed this by pressing 'Reset' in the Dev Region.

Ido
2022-08-17 19:38:01

I tried all of your suggestions and none of them worked can someone help me?

Back to top