Book Image

Learn Unity ML-Agents ??? Fundamentals of Unity Machine Learning

Book Image

Learn Unity ML-Agents ??? Fundamentals of Unity Machine Learning

Overview of this book

Unity Machine Learning agents allow researchers and developers to create games and simulations using the Unity Editor, which serves as an environment where intelligent agents can be trained with machine learning methods through a simple-to-use Python API. This book takes you from the basics of Reinforcement and Q Learning to building Deep Recurrent Q-Network agents that cooperate or compete in a multi-agent ecosystem. You will start with the basics of Reinforcement Learning and how to apply it to problems. Then you will learn how to build self-learning advanced neural networks with Python and Keras/TensorFlow. From there you move o n to more advanced training scenarios where you will learn further innovative ways to train your network with A3C, imitation, and curriculum learning models. By the end of the book, you will have learned how to build more complex environments by building a cooperative and competitive multi-agent ecosystem.
Table of Contents (8 chapters)

To get the most out of this book

The following is a short list of the tools and attributes that may make you more successful as you explore this book:

  • Computer: A desktop computer capable of running Unity, but all the samples are basic enough that even a low-end machine should be sufficient. Check the Unity documentation for the minimum requirements to run Unity.
  • Patience: You may need to train agents for several hours, so expect to wait. Just remember that your patience will be rewarded (Alton Brown). The better your machine, the less you wait, so there's also that.
  • GPU: Don't fret if your computer does not have a support GPU to run TensorFlow; you can run the samples without it. It is nice to have, though.
  • High-school math: If you need to brush up, basic statistics, algebra, and geometry should be sufficient. Developing your own apps will certainly benefit from a better understanding of the mathematics.
  • Programming: A basic understanding of C# is required. You will find it helpful if you also know Unity and Python, but this is not required to run the exercises.

Download the example code files

You can download the example code files for this book from your account at If you purchased this book elsewhere, you can visit and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at Check them out!

Download the color images

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: " This command will create a new 3.5 Python environment named [-n] mlagents. "

A block of code is set as follows:

 void Defend()
currentAction = "Defend";
nextAction = Time.timeSinceLevelLoad + (25 / MaxSpeed);

Any command-line input or output is written as follows:

 conda activate ml-agents

Bold: Indicates a new term, an important word, or words that you see on screen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select System info from the Administration panel."

Warnings or important notes appear like this.
Tips and tricks appear like this.