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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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
  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:
    228
    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");