explaingit

unity-technologies/ml-agents

📈 Trending19,418C#Audience · developerComplexity · 4/5ActiveLicenseSetup · hard

TLDR

Train AI agents in Unity game environments using reinforcement learning. Define what agents can see and do in C#, then use Python to teach them optimal behavior through trial and reward.

Mindmap

mindmap
  root((ML-Agents))
    What it does
      Train AI in games
      Reinforcement learning
      Imitation learning
    How it works
      Unity C# SDK
      Python training loop
      PyTorch algorithms
    Use cases
      Game NPC behavior
      Robotics simulation
      AI research
    Supported algorithms
      PPO and SAC
      Multi-agent scenarios
      Learning from examples

Things people build with this

USE CASE 1

Train NPCs in your game to behave intelligently without hand-coding their logic.

USE CASE 2

Simulate robot behavior in a virtual environment before deploying to real hardware.

USE CASE 3

Run automated playtesting to find bugs and balance issues in your game.

USE CASE 4

Experiment with reinforcement learning algorithms on custom 3D or 2D scenarios.

Tech stack

C#UnityPythonPyTorch

Getting it running

Difficulty · hard Time to first run · 1day+

Requires Unity installation, Python environment with PyTorch, and bridging C#/Python communication for agent training.

Use freely for any purpose, including commercial use, as long as you follow the Apache 2.0 license terms.

In plain English

Unity ML-Agents is an open-source toolkit that lets you use Unity game environments, the same engine used to build video games, as training grounds for teaching AI to make decisions. The core idea is reinforcement learning: instead of programming explicit rules for how an agent (a character, robot, or object) should behave, you let the AI figure out the best actions by trying things out and receiving rewards for success. Unity's 3D, 2D, and VR/AR environments make rich and varied training scenarios easy to set up. The toolkit has two main parts: a C# SDK that you integrate into your Unity scene to define what agents can observe and do, and a Python training library (built on PyTorch) that runs the learning algorithms outside the game. Game developers can use it to control NPCs (non-player characters) with learned behavior or to automatically test their game before release. Researchers can plug in their own algorithms via a Python API. Supported algorithms include PPO and SAC (popular deep reinforcement learning methods) and two imitation learning approaches that let agents learn by watching examples rather than trial and error. Multi-agent scenarios, cooperative teams or competitive opponents, are also supported. You would use ML-Agents when you want to train intelligent behavior in a simulated environment, whether for a game, robotics research, or AI experimentation. The tech stack is Unity (C#) for environments and Python/PyTorch for training.

Copy-paste prompts

Prompt 1
How do I set up a Unity scene with ML-Agents so an agent can learn to move toward a target?
Prompt 2
Show me how to define observations and actions for an agent in the ML-Agents C# SDK.
Prompt 3
What's the difference between PPO and SAC in ML-Agents, and when should I use each one?
Prompt 4
How can I train multiple agents to cooperate or compete against each other in ML-Agents?
Prompt 5
Can I use ML-Agents to teach an NPC in my game to play like a human player?
Open on GitHub → Explain another repo

Generated 2026-05-18 · Model: sonnet-4-6 · Verify against the repo before relying on details.