DEV Community

T Suzuki
T Suzuki

Posted on

Run Unity ml-agents Examples on Mac

Screen Shot 2021-06-20 at 21.15.33

After watching several videos about how reinforcement learning can be demonstrated using Unity's 3D simulated physics, I tried to set up Unity for the first time. After hours of researching and debugging, I finally was able to compile the code to start learning RL. Since this didn't work out of the box and there was no document that summarized the steps and how to debug etc to make this work (some were partial), I am sharing how you can fix these issues.

Firstly, I followed the steps in this tutorial to download/install Unity and clone the repository from ml-agents:
At this time, you should have copied ml-agents/Project/Assets/ML-Agents folder under $PROJ_DIR/Assets folder.
Screen Shot 2021-06-20 at 20.40.41

When you press play at the top, it should succeed but in my case, I faced some compile error such as below:

The type or namespace name 'Input' does not exist in the namespace 'Unity.MLAgents.Extensions'

This means, the extensions are provided from Unity-Technologies/ml-agents repository but this was not copied to the project. So let's copy by going to Window -> Package Manager -> plus icon -> Add package from disk -> Select ml-agents/com.unity.ml-agents.extensions/package.json.

Screen Shot 2021-06-20 at 20.52.08

Screen Shot 2021-06-20 at 20.52.21

If this still gives you error, load ml-agents/com.unity.ml-agents/package.json and select the correct version according to the release notes.

Screen Shot 2021-06-20 at 20.55.31

Then I get an error that IInputActionAssetProvider was not read by the compiler, so once I searched for the code and it looks like there is a macro flag MLA_INPUT_SYSTEM which enables this to be read. This is only available using the Input System of 1.1.0-preview.3 according to this code.

So, I updated Input System's version to 1.1.0-preview.3 in the Package Manager. You cannot preview this version unless you enabled preview in the steps above.

Screen Shot 2021-06-20 at 21.01.58

Lastly, I came across this error:

You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings.

This error occurs because there is a new and old way of handling input system packages. (why is that? I don't know) In my case, this was pointing to a new version whereas it should have been pointing to the old version. So I updated that by going into Edit -> Project Settings -> Player -> Other Settings -> Configuration -> Active Input Handling -> Select Input Manager (Old) instead of Input Manager (New). This asks you if you want to restart and so you restart it. The Both setting doesn't get applied upon restart so you want to verify the setting after you restart Unity. If someone can tell me why that is, I'd be appreciated.

Screen Shot 2021-06-20 at 21.05.33

This finally compiled and worked!

ezgif.com-gif-maker (2)

This is my final Environment State:

  • ml-agents branch: release_18
  • Unity ML Agent version: 2.1.0-exp1
  • Unity ML Agent Extension version: 0.5.0-preview
  • Unity Input System version: 1.1.0-preview.3
  • Active Input Handling: Input Manager (Old)

Happy learning!

Top comments (0)