Hey I am struggling with getting multiplay to work properly. Something i’m doing isn’t right and i’m not sure what. If someone could help me out that would be amazing. Basically here’s what i have so far.
using System;
using UnityEngine;
using Unity.Services.Core;
using Unity.Services.Multiplay;
public class LoadingService : MonoBehaviour
{
#region Fields
// Publics
// Privates
private MultiplayEventCallbacks _multiplayEventCallbacks;
private IServerEvents _serverEvents;
private IServerQueryHandler _serverQueryHandler;
private bool isInitialized = false;
//
private const ushort _DefaultMaxPlayers = 1;
private const string _DefaultServerName = "ElemonstersServer";
private const string _DefaultGameType = "TestGameType";
private const string _DefaultMap = "TestMap";
public ushort currentPlayers;
#endregion
#region Interface
private async void Awake()
{
if (Application.isBatchMode == true)
{
StartBatchmode();
}
else
{
if (UnityServices.State == ServicesInitializationState.Uninitialized)
{
await UnityServices.InitializeAsync();
}
}
}
private async void Update()
{
if (isInitialized == false)
{
_serverQueryHandler = await MultiplayService.Instance.StartServerQueryHandlerAsync(
(ushort)_DefaultMaxPlayers,
_DefaultServerName,
_DefaultGameType,
Application.version,
_DefaultMap);
isInitialized = true;
}
_serverQueryHandler.UpdateServerCheck();
//maybe
LogServerConfig();
}
#endregion
#region Privates
private async void StartBatchmode()
{
// Setup allocations
_multiplayEventCallbacks = new MultiplayEventCallbacks();
_multiplayEventCallbacks.Allocate += OnAllocate;
_multiplayEventCallbacks.Deallocate += OnDeallocate;
_multiplayEventCallbacks.Error += OnError;
_serverEvents = await MultiplayService.Instance.SubscribeToServerEventsAsync(_multiplayEventCallbacks);
await MultiplayService.Instance.ReadyServerForPlayersAsync();
LogServerConfig();
}
private void OnError(MultiplayError error)
{
LogServerConfig();
throw new NotImplementedException();
}
private void OnDeallocate(MultiplayDeallocation deallocation)
{
LogServerConfig();
throw new NotImplementedException();
}
private void OnAllocate(MultiplayAllocation allocation)
{
LogServerConfig();
throw new NotImplementedException();
}
private void LogServerConfig()
{
var serverConfig = MultiplayService.Instance.ServerConfig;
Debug.Log($"Server ID[{serverConfig.ServerId}], AllocationId[{serverConfig.AllocationId}], Port[{serverConfig.Port}], QueryPort[{serverConfig.QueryPort}], LogDirectory[{serverConfig.ServerLogDirectory}]");
}
#endregion
}
When i try to run local i’m getting issues with it looking for the server.json file. This tells me that its not connecting to the unity servers application and thus not getting the server.json file from there.