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

How command line arguments are passed in FPSSample when we start the game?

Discussion in 'FPS.Sample Game' started by JJChai, Nov 29, 2019.

  1. JJChai

    JJChai

    Joined:
    Dec 31, 2016
    Posts:
    2
    Hello,

    I have been studying the FPSSample recently. Currently I'm studying the Game.cs
    In the Awake() method, I stumble across this line :

    Code (CSharp):
    1. var commandLineArgs = new List<string>(System.Environment.GetCommandLineArgs());
    I know what this function does. But the thing I have trouble understanding is how FPSSample passes in the arguments into the command line.
    When I hit "play" in the editor, or click play on a standalone build, some arguments are automatically passed into the command line, to be fetched by System.Environment.GetCommandLineArgs() later on. How does FPSSample do this?

    I have spent quite a lot of time to find the answer. I can't seem to find a .bat file that does this. After analysing console scripts I couldn't find the answer too. I think I don't understand what is going on behind the initialization process.
    Could anyone help? :(
     
    AggressiveMastery likes this.
  2. JJChai

    JJChai

    Joined:
    Dec 31, 2016
    Posts:
    2
    Think I found out what I didn't understand before.

    The System.Environment.GetCommandLineArguments() will always fetch some default arguments when we launch a Unity game, e.g -projectpath, game instance name etc.
    If we want to provide any extra arguments like -batchmode, -serverport etc. we have to do it through command line when launching the game.

    And command line != the console in the FPSSample game. They have nothing to do with each other. Previously I thought they do xd
     
    Ryuuguu and AggressiveMastery like this.