How it works
s&box hot reload has two paths depending on what changed:- IL hot reload (fast path)
- Full assembly reload
When only the bodies of existing methods or property accessors change — and no new types, fields, or members are added — the engine uses IL patching via the
ILHotloadProcessor to swap in the new method implementations without reloading the full assembly.The source generator (Sandbox.Generator) analyses the syntax trees of your compilation. If it detects that only statement blocks have changed, it marks the affected methods with [MethodBodyChangeAttribute] or [PropertyAccessorBodyChangeAttribute] and annotates the assembly with [SupportsILHotloadAttribute]. The engine then patches only those method bodies in-place, leaving all existing object instances untouched.Instance upgrading
TheHotload class (Sandbox.Hotload) manages the upgrade process. It tracks:
- Watched assemblies — scanned for static fields holding instances of old types.
- Watched instances — specific object roots to scan.
IInstanceUpgrader implementations handle the per-type upgrade logic (field migration, default-value injection for newly added fields, etc.). The default upgraders are registered automatically when you pass addDefaultUpgraders: true to the constructor.
What triggers a hot reload
The engine watches your project’s source files. When a.cs file is saved, the compiler is invoked in the background. If compilation succeeds, the hot reload pipeline runs automatically — you do not need to press any button.
Writing hot-reload-friendly components
Most components work with hot reload out of the box. A few patterns help ensure smooth upgrades:Limitations
| Change type | Reason |
|---|---|
| Adding or removing a field | Changes the object memory layout |
| Changing a field type | Requires value migration |
| Adding or removing a method signature | Changes the assembly’s public surface |
Modifying a struct | Structs are value types; in-place patching is unsafe |
Adding a new using directive | Treated as a declaration-level change by the analyser |
| Changing preprocessor symbols | Changes which code is compiled |