Hello, first time posting and looking for advice on where i went wrong. Also using Netcode for Game Objects and Unity’s Multiplay services for the first time and pretty new to network programming in general.
I got the Matchmaker and game server hosting setup following guides and resources on the Internet. However even though its successful in finding and matching tickets between two devices. The server would not move to the next game scene and eventually would debug out a Failed to Connect To Server Error.
The codeblock below is what should run in the server build for the game to move to the next scene after a match is found and also the Initialization for the server and client build to connect to the Game server hosting.
private void MultiplayEventCallbacks_Allocate(MultiplayAllocation obj)
{
Debug.Log("DEDICATED_SERVER MultiplayEventCallbacks_Allocate");
if (alreadyAutoAllocated) {
Debug.Log("Already auto allocated!");
return;
}
SetupBackfillTickets();
alreadyAutoAllocated = true;
var serverConfig = MultiplayService.Instance.ServerConfig;
Debug.Log($"Server ID[{serverConfig.ServerId}]");
Debug.Log($"AllocationID[{serverConfig.AllocationId}]");
Debug.Log($"Port[{serverConfig.Port}]");
Debug.Log($"QueryPort[{serverConfig.QueryPort}]");
Debug.Log($"LogDirectory[{serverConfig.ServerLogDirectory}]");
string ipv4Address = "0.0.0.0";
ushort port = serverConfig.Port;
NetworkManager.Singleton.GetComponent<UnityTransport>().SetConnectionData(ipv4Address, port, "0.0.0.0");
GameMultiplayer.Instance.StartServer();
Loader.LoadNetwork(Loader.Scene.CharacterSelectScene);
}
private async void InitializeUnityAuthentication()
{
if (UnityServices.State != ServicesInitializationState.Initialized)
{
InitializationOptions initializationOptions = new InitializationOptions();
#if !DEDICATED_SERVER
initializationOptions.SetProfile(UnityEngine.Random.Range(0, 10000).ToString());
#endif
await UnityServices.InitializeAsync(initializationOptions);
#if !DEDICATED_SERVER
await AuthenticationService.Instance.SignInAnonymouslyAsync();
#endif
#if DEDICATED_SERVER
Debug.Log("DEDICATED_SERVER LOBBY");
MultiplayEventCallbacks multiplayEventCallbacks = new MultiplayEventCallbacks();
multiplayEventCallbacks.Allocate += MultiplayEventCallbacks_Allocate;
multiplayEventCallbacks.Deallocate += MultiplayEventCallbacks_Deallocate;
multiplayEventCallbacks.Error += MultiplayEventCallbacks_Error;
multiplayEventCallbacks.SubscriptionStateChanged += MultiplayEventCallbacks_SubscriptionStateChanged;
IServerEvents serverEvents = await MultiplayService.Instance.SubscribeToServerEventsAsync(multiplayEventCallbacks);
serverQueryHandler = await MultiplayService.Instance.StartServerQueryHandlerAsync(4, "MyServerName", "KingOfTheArena", "5.6", "Default");
var serverConfig = MultiplayService.Instance.ServerConfig;
if (serverConfig.AllocationId != "") {
// Already Allocated
MultiplayEventCallbacks_Allocate(new MultiplayAllocation("", serverConfig.ServerId, serverConfig.AllocationId));
}
#endif
}
else
{
// Already Initialized
#if DEDICATED_SERVER
Debug.Log("DEDICATED_SERVER LOBBY - ALREADY INIT");
var serverConfig = MultiplayService.Instance.ServerConfig;
if (serverConfig.AllocationId != "") {
// Already Allocated
MultiplayEventCallbacks_Allocate(new MultiplayAllocation("", serverConfig.ServerId, serverConfig.AllocationId));
}
#endif
}
}
If i am lacking in context, i would appreciate in being pointed out.