Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Error in setting up SQP Service

Discussion in 'Game Server Hosting' started by marzdh, Aug 26, 2023.

  1. marzdh

    marzdh

    Joined:
    Jun 3, 2013
    Posts:
    35
    I have followed this tutorial for setting up a dedicated server hosting and matchmaking for Unity for the VR platform.

    As a first client, I am allocated a server id. If I click on the server ID from the dashboard, I see 0 concurrent users. Now if I log in as a second client, I am allocated to another server id with a different port. I continue seeing a 0 concurrent users for that id as well.

    When I see the engine logs, this is the error I think which could be creating a problem -

    Unity.Services.Multiplay.Internal.WrappedMultiplayService
    Something went wrong trying to setup the SQP Service
    System.NullReferenceException: Object reference not set to an instance of an object
    at ServerStartup.StartServerServices () [0x0009e] in <a14e40ef78c34d62abef1fb76589d510>:0
    On Subsrciption changed Subscribing

    The code from where the above logs are shown
    Code (CSharp):
    1. async void Start()
    2.     {
    3.         bool server = false;//checks to see if it is the server.
    4.         var args = System.Environment.GetCommandLineArgs();
    5.         for(int i=0; i<args.Length; i++)
    6.         {
    7.             if (args[i] == "-dedicatedServer")
    8.             {
    9.                 server = true;
    10.             }
    11.             if (args[i] =="-port" && (i+1) < args.Length)
    12.             {
    13.                 ServerPort = (ushort)int.Parse(args[i+1]);
    14.             }
    15.             if (args[i] == "-ip" && (i + 1) < args.Length)
    16.             {
    17.                 ExternalServerIP = args[i + 1];
    18.             }
    19.         }
    20.         if(server)
    21.         {
    22.             StartServer();
    23.             await StartServerServices();
    24.             await MultiplayService.Instance.ReadyServerForPlayersAsync();
    25.         }
    26.         else
    27.         {
    28.             ClientInstance?.Invoke();
    29.         }
    30.     }
    31.  
    32.     private void StartServer()
    33.     {
    34.         NetworkManager.Singleton.GetComponent<UnityTransport>().SetConnectionData(
    35.             InternalServerIP, ServerPort, "0.0.0.0");
    36.         NetworkManager.Singleton.StartServer();
    37.         NetworkManager.Singleton.OnClientDisconnectCallback += ClientDisconnected;
    38.         Debug.Log("Server Started");
    39.     }
    40.  
    41.    
    42.     async Task StartServerServices()
    43.     {
    44.         await UnityServices.InitializeAsync();
    45.         //Connecting to the Unity Gaming Services
    46.         try
    47.         {
    48.             _multiplayService = MultiplayService.Instance;
    49.             Debug.Log(_multiplayService.ToString());
    50.             m_ServerQueryHandler = await _multiplayService.StartServerQueryHandlerAsync(
    51.                 (ushort)LobbyInGame.instance.GetMaxPlayers(), "n/a", "n/a", "0", "n/a");
    52.             Debug.Log(m_ServerQueryHandler);
    53.         }catch(Exception ex)
    54.         {
    55.             Debug.LogWarning($"Something went wrong trying to setup the SQP Service\n{ex}");
    56.         }
    57.  
    58.         //Connecting to the Matchmaker Services
    59.  // ...
    60.     }
    My reference to build this experience is the video from youtube How to Setup Dedicated Server Hosting and Matchmaking for Unity - YouTube
     
  2. mariamdh

    mariamdh

    Joined:
    Aug 24, 2023
    Posts:
    2
    I figured the solution.
    In StartServerQueryHandlerAsync() method, we need to mention a maximum player count. The method I was calling was returning a null value. Once that was sorted, the SQP service started working.