Search Unity

Pass custom parameters to standalone on launch

Discussion in 'Scripting' started by eco_bach, Sep 2, 2016.

  1. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Hi
    I know you can use Command line arguments to pass default values to either the Unity editor OR a Unity standalone executable on launch
    https://docs.unity3d.com/Manual/CommandLineArguments.html

    However, I want to pass CUSTOM values, say 'showdebugging = false' or 'username=fred'. Can anyone tell me how to do this?
     
  2. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    You mean like this? <bad link removed>
     
    Last edited by a moderator: Jan 15, 2024
  3. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Thanks. Good article
     
  4. the_mr_matt

    the_mr_matt

    Joined:
    Jul 21, 2015
    Posts:
    124
    Link no longer works.
     
  5. glenneroo

    glenneroo

    Joined:
    Oct 27, 2016
    Posts:
    231
    Link is password protected :(
     
  6. jj_unity328

    jj_unity328

    Joined:
    Jun 7, 2018
    Posts:
    22
    And that's why archive.org exists, kids!

    Basically:

    Code (CSharp):
    1. private static string GetArg(string name)
    2. {
    3.     var args = System.Environment.GetCommandLineArgs();
    4.     for (int i = 0; i < args.Length; i++)
    5.     {
    6.         if (args[i] == name && args.Length > i + 1)
    7.         {
    8.             return args[i + 1];
    9.         }
    10.     }
    11.     return null;
    12. }
    and then:

    Code (CSharp):
    1. // Eg:  C:\Program Files\Unity\Unity.exe -outputDir "c:\temp\output" ...
    2. // read the "-outputDir" command line argument
    3. var outputDir = GetArg ("-outputDir");