Run code after a patch¶
Want to refresh UI, reset a cache, or log what changed whenever a patch succeeds? Mark a method with [InvokeOnHotPatch].
Turn the feature on or off in Settings → Invoke [InvokeOnHotPatch] methods (on by default).
Quick example¶
using System.Collections.Generic;
using DivinityCodes.HotPatch;
using UnityEngine;
public class GameBootstrap : MonoBehaviour
{
[InvokeOnHotPatch]
static void OnHotPatch(IReadOnlyList<HotPatchMethodPatch> patches)
{
foreach (var patch in patches)
Debug.Log($"Patched {patch.TypeFullName}.{patch.MethodName}");
}
}
Static vs instance methods¶
| Kind | When it runs |
|---|---|
| Static | Once after a batch of successful patches |
| Instance | On every live MonoBehaviour of that type in the scene |
Allowed signatures¶
All of these are valid (must return void):
void OnHotPatch()
void OnHotPatch(IReadOnlyList<HotPatchMethodPatch> patches)
void OnHotPatch(HotPatchMethodPatch[] patches)
void OnHotPatch(List<HotPatchMethodPatch> patches)
The patch list is optional. Patches applied in the same frame arrive together.
Useful fields on each HotPatchMethodPatch: AssemblyName, TypeFullName, MethodName, MethodSignature, PatchedMethod.
Rules of thumb¶
- Only successful patches trigger the callback
- Skipped or failed patches do not
- Renaming a method counts as delete + add - handlers are not invoked for that
- The attribute is not inherited; put it on each method you care about