Skip to content

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Training a smart agent in Unity

Hi guys i just wanted to learn how to incorporate machine learning into my Unity projects. I watched this tutorial from Code Monkey but slightly modified it to work in 2026 since the vid is pretty old. My friends were interested in learning how to do this too so I'm writing this detailed readme for them but if you happen to stumble upon this I hope its somewhat useful or interesting. Untitleddesign2-ezgif com-video-to-gif-converter

Set-up & install instructions

Ok so this is the official doc with all the install instructions but I did it slightly differently. I'll write down how I did it but please note I am using Unity 6 with Windows 11 so there may be variations across different OSs. Also, im not going over the stuff done in the Unity editor. You can find that information in the video and documentation.

  • First you wanna install Python 3.10 (My first mistake was attempting using Python 3.14)
  • Make a folder for your project. You'll build your Unity project here as well as set up a virtual environment
  • cd to your folder and type py -3.10 -m venv venv to create your virtual environment
  • activate with venv\Scripts\activate
  • now that you're in the virtual environment, write these commands in order:
  1. pip install mlagents==1.1.0
  2. pip install "torch==2.2.2" --index-url https://download.pytorch.org/whl/cu121
  3. mlagents-learn --help (this is just to check if its installed)

To run and start training the agent type:

mlagents-learn

This should pop up. Press play in the editor to start training. image

After running the first time you may notice an error preventing you from running again. In subsequent runs, type either:

  • mlagents-learn --run-id=[your choice]
  • mlagents-learn --force

I'm gonna assume you have Unity (6) installed and C# .NET stuff setup since this is a unity project afterall but if you don't here's some material:

About

Training a smart agent using reinforcement learning in Unity

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages