Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Starting a Server via Command Line doesn't seem to work

Discussion in 'Netcode for GameObjects' started by porkchopsandwitches, Jan 19, 2022.

  1. porkchopsandwitches

    porkchopsandwitches

    Joined:
    May 11, 2020
    Posts:
    2
    Been working on this for a couple of days and can't seem to find any other posts on it.

    I'm working on getting a headless build for my game. I've added the following code to start a server with the command line arg of -server-only

    Code (CSharp):
    1.     private void Awake()
    2.     {
    3.         Application.targetFrameRate = 60;
    4.  
    5.         string[] args = System.Environment.GetCommandLineArgs();
    6.         for (int i = 0; i < args.Length; i++)
    7.         {
    8.             if (args[i] == "-server-only")
    9.             {
    10.                 NetworkManager.Singleton.StartServer();
    11.                 Debug.Log("Server Started");
    12.             }
    13.  
    14.         }
    15.     }
    When I start the game this way I get a NullReferenceException on the NetworkManager.Singleton.StartServer(); call. Any ideas?
     
  2. porkchopsandwitches

    porkchopsandwitches

    Joined:
    May 11, 2020
    Posts:
    2