OnMasterServerEvent is only called in some classes

I have a pretty interesting problem. I’m currently working on a multiplayergame and I’ve used the default Unity Master Server. It went pretty well until yesterday. Everything worked fine but when I tested the game again, the OnMasterServerEvent wasn’t called anymore. I’ve tried to figure out why this problem appears but the only thing I’ve figured out was that the event gets called in some other classes.

Does anyhone have a solution for this problem? I mean it’s pretty strange that the code just stops working without any changes…

My Code:

public class NET_OnlineManager : MonoBehaviour {

void OnMasterServerEvent(MasterServerEvent msEvent)
    {

        if (msEvent == MasterServerEvent.HostListReceived)
        {

            if (!NET_ServerSetup.checkForEqualNames)
            {
                NET_Serverlist.hostList = MasterServer.PollHostList ();
                GameObject.Find("Skripte").GetComponent<NET_Serverlist>().calculateButtonPositions ();
            }
}

}

}

public class NET_Serverlist : MonoBehaviour {

    public GameObject musterButton;

    public static HostData[] hostList;

    public void refreshServerlist()
    {

        MasterServer.ClearHostList ();
        MasterServer.RequestHostList (NET_OnlineManager.GAMENAME);

    }

    public void calculateButtonPositions()
    {

        GameObject[] allButtons = GameObject.FindGameObjectsWithTag ("JoinButton");

        foreach (GameObject jButton in allButtons)
            Destroy (jButton);

        for (int i = 0; i < hostList.Length; i++)
        {

            GameObject newButton = Instantiate (musterButton, musterButton.transform.position, musterButton.transform.rotation, musterButton.transform.parent) as GameObject;
            newButton.transform.position = new Vector3 (newButton.transform.position.x, newButton.transform.position.y - (i * 20), newButton.transform.position.z);
            newButton.GetComponent<Button> ().onClick.AddListener (delegate { NET_OnlineManager.ConnectToServer(hostList[i]); });
            newButton.GetComponentInChildren<Text> ().text = hostList [i].gameName;
            newButton.GetComponentInChildren<Text> ().enabled = true;
            newButton.GetComponent<Button> ().enabled = true;
            newButton.GetComponent<Image> ().enabled = true;
            newButton.name = "Join Button " + (i+1);
            newButton.tag = "JoinButton";

            if (i == (hostList.Length - 1))
                break;

        }

    }

}

I think you only get that call on NetworkBehaviours, right??

https://docs.unity3d.com/ScriptReference/Networking.NetworkBehaviour.html

Your script appears to be inheriting MonoBehaviour.

I’ve not done much in unity networking but that sorta smells right.

Nope, it also works on MonoBehaviours.

NetworkBehaviour is UNet. MasterServer is the obsolete old networking system.

Which does beg the question…why are you using the legacy solution? :slight_smile:

Wait… The MasterServer is part of the old system? Seems like I haven’t realized that it got replaced. :eyes:

Yeah - new system is all web service based.

https://docs.unity3d.com/ScriptReference/Networking.NetworkManager.StartMatchMaker.html

1 Like

Oh, I didn’t know that. Thank you for the hint! I’ll redo my code to fit in this system!