- Home /
Read Command Line Arguments
Hey all,
How can I have my Unity3D client read it's processes' start arguments? This is on windows. I want it to read its arguments so that I can pass additional info to the client when starting it with a launcher I built.
Thanks, Christian
Unfortunately, it is not supported for console platform such as PS4.
Answer by Taylor-Libonati · Sep 22, 2016 at 10:47 PM
Here is what I used for anyone looking. Just replace -folderInput with whatever tag you are looking for
string[] args = System.Environment.GetCommandLineArgs ();
string input = "";
for (int i = 0; i < args.Length; i++) {
Debug.Log ("ARG " + i + ": " + args [i]);
if (args [i] == "-folderInput") {
input = args [i + 1];
}
}
Answer by SilverTabby · Jul 02, 2011 at 09:40 PM
It sounds like what you are looking for is
System.Environment.CommandLine
System.Environment.CommandLineArgs
The Environment class is part of the .NET framework, so you have to import it by hand at the start of the script. Also keep in mind these two functions are not available in web-player builds.
For more information on .NET classes and functions and where they can be used, read the MonoCompatibility page in the scripting reference (It's a big one).
That's the way I used in my game, Unity silently ignores any unknown parameter so it's safe to add your own. To keep it clear from unity commands I prefixed all by commands with a + ins$$anonymous$$d of -, example:
-batch$$anonymous$$ode -execute$$anonymous$$ethod Build.CommandLine$$anonymous$$ake +buildLocation Build/Output/WebPlayer +buildTarget WebPlayer
Up ! :o
As Capyvara said, i would like to access the parameters of my app, is there like a dictionnary where i could find the value of the key:"buildTargetWebPlayer" (in this case ?)