Working with Unity
C# hot reload
What hot reload changes in a running Play Mode session, what still needs a normal recompile, and how to turn it on.
The usual loop is stop Play Mode, compile, reload the domain, press Play and replay your way back, and an agent that writes five fixes pays for it five times. With hot reload, changed method bodies patch into the running game, so a one-line fix doesn't cost you the scene or the bug you just reproduced.
What reloads
- Method bodies, during Play Mode.
- In Assembly-CSharp, your asmdefs and embedded packages.
- Whether you edit the file yourself or an agent writes it to disk.
Method bodies are patched into the running Mono domain without a domain reload, so objects and connections stay, and the new code runs the next time the method is called. The primary's hot reload reaches every multiplayer clone, so you don't relaunch four players.
What needs a normal recompile
- New fields, methods and types.
- Changed signatures.
- New handles.
For those, stop Play Mode and let Unity recompile. A patched Awake or Start only affects objects spawned afterwards.
Turn it on
Hot reload is a toggle in the Unity Player panel. Agents turn on the same toggle with hotReload: true:
await unity.play('Assets/Scenes/Pond.unity', { hotReload: true })
Then an agent saves a .cs file and calls its handles again. You can do the same: change the code behind a jump and keep playing the match that never stopped. Hot reload errors show up in the console as [HotReload] ....
Without hot reload, .cs changes don't compile in Play Mode.
Requirements
Hot reload needs Unity 6 on Mono, which the editor uses. It doesn't work with IL2CPP, and your IL2CPP player builds are unaffected.
The rest of the live scene
For changes that aren't code, an agent runs C# in the session through Roslyn with unity.exec: spawn objects, change values, call your handles. In Play Mode those scene changes are gone on Stop, like any Play Mode edit. See The MCP server.