Skip to main content

Unity ML Agents

Downloads
Download

Download the latest release from this Github page

image.png

unzip

unzip it to C:\Users\YOUR USERNAME\  (Windows)

For Linux and Mac save unzip it to 'home' directory

now you will have a folder there called: ml-agents-release_20

Installations: Anaconda and Python


  1. Install Anaconda but don't add it to PATH
  2. Install Python and add to PATH during the installation.

image.png

Anaconda itself is a Python distribution, but it is not recommended to add it to path. We install Python after our Anaconda installation so that python commands can be executed systemwide, but conda commands only when using conda shell, to prevent any interference with other applications using Python.

Conda environment configuration
create conda environment
conda create -n ml-agents python=3.8


activate conda environment

conda activate ml-agents


install pytorch

image.png


install Unity ML Agents:

cd ml-agents-release_20/ml-agents-release_20
pip3 install -e ./ml-agents-envs
pip3 install -e ./ml-agents


Downgrade protobuf and install onnx module

pip install protobuf==3.20
pip install onnx

Unity project configuration

Create a new unity 3D project with an editor version later than 2020 here I use 2021.03.15f1

image.png

Under "Location" choose the ml-agents-release-20 folder that you have in your home directory. 


in the newly created Unityproject Install the ML Agents Unitypackage:

aa_ml_agents_2.gif

Go to window -> package manager -> + -> install from disk

navigate to C:/Users/ml-agents-release-20/ml-agents-release-20/com.unit.ml-agents and click on the package.json


Copy the ml agents assets to your unity project

in your file system navigate to

C:\Users\YOUR_USERNAME\ml-agents-release_20\ml-agents-release_20\Project\Assets

find the folder ML-Agents 📁 and drag it into your newly created and open unity project into the 'Assets' window.

image.png


Training the agents
activate the conda environment
conda activate ml-agents
start the training with conda shell
cd ml-agents-release_20/ml-agents-release_20
mlagents-learn config/ppo/Walker.yaml --run-id=walker-001

Unity ML Agent Documentation

[experiment] copying movement to a humanoid character

humanoid character *.fbx 

script for copying rotation and location:

using UnityEngine;

public class FollowObject : MonoBehaviour
{
    public GameObject objectToFollow;
    public Vector3 offset;
    public bool copyPosition = true;
    public bool copyRotation = true;

    private void Update()
    {
        if (copyPosition)
        {
            transform.position = objectToFollow.transform.position + offset;
        }

        if (copyRotation)
        {
            transform.rotation = objectToFollow.transform.rotation;
        }
    }
}