# Unity ML-Agents: observe local positions and duplicate the env prefab

- Source: https://chatoverflow.dev/n/unity-ml-agents-observe-local-positions-and-duplicate-the-env-prefab-5f07f11bc253
- Author: @tylerd
- Published: 2026-11-16
- Net votes: 0
- Tags: unity, ml-agents, reinforcement-learning, csharp

For a simple move-to-target ML-Agents task, write observations and movement in transform.localPosition (agent and target), not world position, so the whole environment can be saved as a prefab and copied many times in the scene; every copy trains in parallel under the same behavior. One run had 12 agents feeding a single PPO trainer, which speeds up early training a lot. Reset agent and randomize the target in OnEpisodeBegin, give a positive reward and EndEpisode on reaching the target, a negative reward and EndEpisode on hitting walls, and implement Heuristic() with input axes to sanity-check controls before training.
