This one script controlling the region my game is connected to freezes Unity Editor.

Options
Every time I either edit a script and am on a scene with this script it hangs. Every second time I press play on a scene with this script it hangs. I'm 100% certain its this script. Also, its specifically the start Connect region and the OnDisconnectedFromPhoton. Its said to be a thread problem or something to do with a dll but I dont know how to deal with that. Thats why I'm asking for help. Please. Heres the code


public class PhotonRegion : MonoBehaviour {

public TextMeshProUGUI regionLabel;
public TextMeshProUGUI regionID;
public bool noRegionSetTest = false;

string versionNumber = GameProperties.versionNumber;

[SerializeField]
private string regionToConnectTo;

void Start()
{
#region //Connect

regionToConnectTo = PlayerPrefsManager.GetGameRegion();

if (regionToConnectTo == "")
{
print("region to connect to is null");
PlayerPrefsManager.SetGameRegion("EU");
print("set game region in playerprefs to EU");
regionToConnectTo = PlayerPrefsManager.GetGameRegion();
}

if (!PhotonNetwork.connected)
{
print("NOT CONNECTED");
if (regionToConnectTo == "US")
{
PhotonNetwork.ConnectUsingSettings(versionNumber);
PhotonNetwork.networkingPeer.ConnectToRegionMaster(CloudRegionCode.us);
PlayerPrefsManager.SetGameRegion(regionToConnectTo);
print("Region is us");
}
/// Its this same thing for each region code^

print(regionToConnectTo);
}

#endregion
regionID.text = "Current Region is " + PlayerPrefsManager.GetGameRegion();
regionLabel.text = PlayerPrefsManager.GetGameRegion();

//PlayerPrefsManager.SetGameRegion(PhotonNetwork.networkingPeer.CloudRegion.ToString());
}

void OnDisconnectedFromPhoton()
{
if(regionToConnectTo == "US")
{
PhotonNetwork.ConnectUsingSettings(versionNumber);
PhotonNetwork.networkingPeer.ConnectToRegionMaster(CloudRegionCode.us);
PlayerPrefsManager.SetGameRegion(regionToConnectTo);
print("Region is us");
regionID.text = "Current Region is " + PlayerPrefsManager.GetGameRegion();
regionLabel.text = PlayerPrefsManager.GetGameRegion();
}

/// Its this same thing for each region code^
}

//SetRegion

void FixedUpdate()
{
print(PlayerPrefsManager.GetGameRegion());
}
}

Comments

  • Hi @Aminushki,
    PhotonNetwork.ConnectUsingSettings(versionNumber);
    PhotonNetwork.networkingPeer.ConnectToRegionMaster(CloudRegionCode.us);
    These are two calls which are doing mostly the same. It is enough to only use one of them. This maybe also freezes the Unity Editor (I'm not sure about that).

    About the other problem you are facing: Please note, that every time you make changes to your scripts, Unity (re-)-compiles those scripts, when the Editor gets focused again which might take a second or two.

    Please feel free to ask again, if this doesn't solve the problem.