Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party Photon's PUN 2 Error

Discussion in 'Multiplayer' started by SebGM2019, Oct 23, 2018.

  1. SebGM2019

    SebGM2019

    Joined:
    Aug 3, 2018
    Posts:
    34
    I have a problem here with Photon's PUN 2. Sometimes It works, but other times it doesn't. Since the last 2 weeks it isn't working that fine. Before it were better, I joined to the master, and then, to the lobby and It allowed me to list the rooms and join them without any problem. Now, I haven't changed that code that much, I only changed it after the errors started. Now, sometimes it joins a match, but another it doesn't, showing the following error:

    JoinRandomRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.

    I only have 2 devices to test my online with PUN, but, even if I created a room is not working anymore, it just seems like works randomly. Here's my code if you want to check it:
    Code (CSharp):
    1. void Start()
    2. {
    3. PhotonNetwork.ConnectUsingSettings();
    4. }

    5. // Update is called once per frame
    6. void Update()
    7. {

    8. }
    9. public override void OnJoinedLobby()
    10. {
    11. // /* print("Connected to lobby")*/;

    12. }
    13. public override void OnConnectedToMaster()
    14. {
    15. //This shows a popup to let know the player that is connected
    16. //PhotonNetwork.JoinLobby();
    17. base.OnJoinedLobby();
    18. GameObject.Find("IWifi").SetActive(false);
    19. print("Puga");
    20. StatePScript.IsShow = true;
    21. Connected = true;
    22. GameObject.Find("IOk").GetComponent<Image>().color = Color.white;
    23. print("IOKS Value is " + IOKS.Show);
    24. GameObject.Find("StatusText").GetComponent<Text>().text = "Connected!";
    25. GameObject.Find("StatusText").GetComponent<Text>().color = Color.green;
    26. A.Play();
    27. GameObject.Find("StatePanel").GetComponent<Animator>().SetBool("Show", false);
    28. IOKS.Show = false;
    29. GameObject.Find("IOk").GetComponent<Image>().color = new Color(0, 0, 0, 0);
    30. Connected = false;
    31. StatePScript.IsShow = false;
    32. }
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    This is a timing issue, which you can control with the way you test. Connecting to the Photon Cloud is a "process" and if you call operations (like Join) before the process is done, you get this sort of error.
    The client's logic can be improved to wait for the callback OnConnectedToMaster, before it enables the "find game" button (or whatever you use to create/join rooms).

    The minimal logic to get into a room is in ConnectAndJoinRandom.cs.