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. Dismiss Notice

Sending information through side channel from Python to Unity before env.step or env.reset

Discussion in 'ML-Agents' started by rg18, Nov 6, 2020.

  1. rg18

    rg18

    Joined:
    Aug 29, 2020
    Posts:
    14
    Prior to the game running, I would like to pass the path of a config file from Python to Unity. In the documentation, it states side channels only send information when env.step or env.reset is called. Therefore it seems that until a step occurs, no information can be shared between Python and Unity. To get around this, I simply call Academy.Instance.EnvironmentStep at the beginning of the Awake function for the object in Unity, then reset the environment in python. This works, but it seems very hacky and not ideal. Is there any other way to do this?

    Note: I would hard code the path of the config file but that does not work for the purposes of the game.
     
  2. jeffrey_unity538

    jeffrey_unity538

    Unity Technologies

    Joined:
    Feb 15, 2018
    Posts:
    59
    hi @rg18 - thank you for reaching out.

    i think the best option would be for you to use the --env-args options when you run mlagents-learn.

    --env-args ... Arguments passed to the Unity executable. Be aware
    that the standalone build will also process these as
    Unity Command Line Arguments. You should choose
    different argument names if you want to create
    environment-specific arguments. All arguments after
    this flag will be passed to the executable. (default:
    None)

    You can write logic to grab that path of a config file as a Unity Command Line Argument in your code. Let me know if that would work for you.

    Jeff
     
  3. rg18

    rg18

    Joined:
    Aug 29, 2020
    Posts:
    14
    This is great, but ideally I would like to be able to do this within the editor too. Based on the description of that command, the mlagents_envs.environment.UnityEnvironment code, and the following forum answer: https://answers.unity.com/questions/537730/how-do-i-run-in-editor-with-command-line-arguments.html, it seems there is no way to do this. Am I mistaken? Is this actually possible?