Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Passing additional arguments when launching an executable

Discussion in 'ML-Agents' started by camigord, Oct 19, 2020.

  1. camigord

    camigord

    Joined:
    May 29, 2019
    Posts:
    7
    Hi,
    I am trying to use the
    additional_args
    parameter when instantiating a
    UnityEnvironment()
    but it doesn't look like I am receiving that parameter in the environment.

    In Python:
    Code (CSharp):
    1. additional_args = []
    2. additional_args += ["--test_arg"]
    3. env = UnityEnvironment(..., additional_args=additional_args)
    4.  
    In Unity (3DBall scenario, inside Ball3DAgent.Initialize())

    Code (CSharp):
    1. var sr = File.CreateText(fileName);
    2. string[] args = System.Environment.GetCommandLineArgs();
    3. for (var i = 0; i < args.Length - 1; i++)
    4. {
    5.       sr.WriteLine(args[i]);      
    6. }
    7. sr.Close();
    As you can see, I am generating a text file with all the received arguments, but so far I only see the path to the executable and
    --mlagents-port 5005


    Any ideas what could be happening?
     
  2. vincentpierre

    vincentpierre

    Joined:
    May 5, 2017
    Posts:
    160
    Hi,

    There is a bug in the code you are using to retrieve the arguments:
    Replace
    for (var i = 0; i < args.Length - 1; i++)
    with
    for (var i = 0; i < args.Length; i++)
    Let us know if there is still an issue.
     
  3. camigord

    camigord

    Joined:
    May 29, 2019
    Posts:
    7
    Oh wow, how did I miss that. Thanks!