Help getting Multiplay working

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.

Hello,

The server.json file is something that is created when you run your game server on Multiplay. Running the server locally will return an error if that file does not exist.

You have two options here:

  1. Create some logic in your code to check if you are running locally (maybe a -local flag) and then bypass the code looking for server.json when running locally
  2. Create an example server.json on your local machine. See Server.json for the format and file location

does that mean that anytime i try to reference Multiplay.Instance it will fail? because thats the bit of code giving the error.

        if (isInitialized == false)
        {
            _serverQueryHandler = await MultiplayService.Instance.StartServerQueryHandlerAsync(
                (ushort)_DefaultMaxPlayers,
                _DefaultServerName,
                _DefaultGameType,
                Application.version,
                _DefaultMap);
            isInitialized = true;
        }
        _serverQueryHandler.UpdateServerCheck();

this is the primary offender, when i’m trying to start the query handler.