No match found - Join Random Room
Options
No matter what I try, both clients create separate rooms and when calling to join random they both say no match found.
using UnityEngine; using Photon.Pun; using Photon.Realtime; public class MenuNetwork : MonoBehaviourPunCallbacks { public static MenuNetwork Network; private void Awake () { Network = this; } [Header("Adjustable")] public float maxWaitTime = 20f; public bool debugMode = false; public float fakeDelay = 1f; public int levelToLoad = 1; [Header("References")] public GameObject connectingUI; public GameObject quickmatchButton; public GameObject searchingUI; [Header("Observe Only")] [SerializeField] private float delay; [SerializeField] private bool searching = false; [SerializeField] private float waitTimer; private void Start () { delay = fakeDelay; waitTimer = maxWaitTime; PhotonNetwork.AutomaticallySyncScene = true; PhotonNetwork.ConnectUsingSettings(); } public override void OnConnectedToMaster() { if(debugMode) Debug.Log("(Network) Connected to Master Server"); CreateRandomUsername(); connectingUI.SetActive(false); quickmatchButton.SetActive(true); } private void CreateRandomUsername () { PhotonNetwork.NickName = "User " + Random.Range(100, 10000).ToString("N0"); } public void OnClick_Quickmatch() { searching = true; quickmatchButton.SetActive(false); searchingUI.SetActive(true); } public void OnClick_Cancel () { searching = false; PhotonNetwork.LeaveRoom(); quickmatchButton.SetActive(true); searchingUI.SetActive(false); } private void Update () { if(searching) { delay -= Time.deltaTime; if (delay <= 0) { searching = false; PhotonNetwork.JoinRandomRoom(); delay = fakeDelay; } } // end of if searching // DEBUGGING if(PhotonNetwork.InRoom) { Debug.Log("Is Host? " + PhotonNetwork.IsMasterClient); Debug.Log("Players: " + PhotonNetwork.CurrentRoom.PlayerCount + "/" + PhotonNetwork.CurrentRoom.MaxPlayers); } if(PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient) { // If there are 2 or more players if(PhotonNetwork.CurrentRoom.PlayerCount > 1) { waitTimer -= Time.deltaTime; if (waitTimer <= 0) { Host_StartMatch(); waitTimer = maxWaitTime; return; } // If we're at the max players if (PhotonNetwork.CurrentRoom.PlayerCount == PhotonNetwork.CurrentRoom.MaxPlayers) { waitTimer = maxWaitTime; Host_StartMatch(); return; } } } // end of if in room & host } public override void OnJoinRandomFailed(short returnCode, string message) { Debug.Log("OnJoinRandomFailed: " + message); CreateRandomRoom(); } private void CreateRandomRoom () { int generatedID = Random.Range(0, 9999999); RoomOptions roomOptions = new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = 4 }; PhotonNetwork.CreateRoom("Quickmatch " + generatedID.ToString("N0"), roomOptions); //PhotonNetwork.CreateRoom(null); } public override void OnCreateRoomFailed(short returnCode, string message) { base.OnCreateRoomFailed(returnCode, message); Debug.LogError("Failed to create room? Trying again!"); CreateRandomRoom(); } public override void OnJoinedRoom() { Debug.Log("(Network) Connected to room " + PhotonNetwork.CurrentRoom.Name); searching = false; } private void Host_StartMatch () { PhotonNetwork.LoadLevel(levelToLoad); } }
0
Comments
-
Hi @kriller509,
Make sure both clients are connected to the same Region, AppId and AppVersion. Read "Matchmaking Checklist".
If you try to join random room at the same time (click "Quickmatch") then yes this is expected. Try to wait a little bit from the second client to give some time for the room to finish creation first server side.
I don't see why you haveJoinRandomRoom
logic in Update? You can just call it insideOnClick_Quickmatch
.
0 -
JohnTube said:
Hi @kriller509,
Make sure both clients are connected to the same Region, AppId and AppVersion. Read "Matchmaking Checklist".
If you try to join random room at the same time (click "Quickmatch") then yes this is expected. Try to wait a little bit from the second client to give some time for the room to finish creation first server side.
I don't see why you haveJoinRandomRoom
logic in Update? You can just call it insideOnClick_Quickmatch
.
Thank you for your reply. In regards to update it's there because there is a delay timer before the search actually begins in order to give people time to cancel.
As for simultaneous quickmatch, I am aware that is a problem and yes I do wait. Still when I try to play with my friend we are placed into separate rooms.
And yes, AppID, AppVersion are the same. As for region, I have not messed with that whatsoever and both clients are running on the same build so I should think they'd be in the same region? We both live in the U.S after all.0 -
Is there any way to have diff regions connect to each other? I'm a bit annoyed that me in Michigan and my friend in Texas can't connect to each other.JohnTube said:As for region, I have not messed with that whatsoever and both clients are running on the same build so I should think they'd be in the same region? We both live in the U.S after all.You can end up on two different regions. Read more here.0 -
Players connected to different regions can't play with each other.
First, you need to be sure that the matchmaking issue is due to the fact that you and your friend are connected to different regions. Log the region once connected, e.g.:void OnConnectedToMaster() { Debug.LogFormat("Region {0}", PhotonNetwork.NetworkingClient.CloudRegion); }
Michigan is probably closer to Washington DC ("US" region servers, US east)
Texas is probably closer to San José ("USW" region servers, US west)
If you want to avoid this:
- set a specific region in PhotonServerSettings
- use Regions Whitelisting to allow only US or USW1 -
Wouldn't that mean that all players would be forced to U.S servers?JohnTube said:
If you want to avoid this:
- set a specific region in PhotonServerSettings
- use Regions Whitelisting to allow only US or USW0 -
I tried whitelisting but all that did was making so only people in the U.S could connect whatsoever. I just want so me and my friend can play together even though he's in Texas, like is that really not something that's possible?JohnTube said:
- use Regions Whitelisting to allow only US or USW
I have a paid license with my other game that uses Realtime instead of Bolt and me and my friend can play on that just fine, so is it just a Bolt thing?
The reason I picked bolt was because I wanted players to host their own dedicated servers from like a console like every other game that uses port forwarding.0 -
Bolt?
I have moved this discussion to Bolt category.
You should have said that you are using Bolt since the beginning.0 -
The code at the top is PUN so I can’t help with that. Let us know if you have Bolt related question0
-