I am currently working on a game that uses Netcode for GameObjects
.
I need a way to make sure that players on an outdated client can not join a Lobby
/ Relay
session.
Does anyone know how to do this?
I am currently working on a game that uses Netcode for GameObjects
.
I need a way to make sure that players on an outdated client can not join a Lobby
/ Relay
session.
Does anyone know how to do this?
I found the solution.
You can make a Github repo with a txt file that only contains the version number, then receive that number in game using Unity Web Requests. You can then create a variable containing the client version number, if they do not match, the player is on an outdated client. If anyone needs it, here is my code for this:
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public class CheckVersion : MonoBehaviour
{
public static int clientVersion = 5;
[SerializeField] private string web_url;
[SerializeField] private GameObject incorrectVersionScreen;
private IEnumerator Start()
{
using(UnityWebRequest unityWebRequest = UnityWebRequest.Get(web_url))
{
yield return unityWebRequest.SendWebRequest();
if(unityWebRequest.result == UnityWebRequest.Result.ConnectionError || unityWebRequest.result == UnityWebRequest.Result.ProtocolError)
{
Debug.Log("Error fetching web content");
}
else
{
int recievedVersion = -1;
int.TryParse(unityWebRequest.downloadHandler.text, out recievedVersion);
Debug.Log("Recieved version " + recievedVersion);
if(clientVersion != recievedVersion)
{
incorrectVersionScreen.SetActive(true);
Time.timeScale = 0f;
}
}
}
}
}