Info
- The project enters play mode without a domain reload, so static fields keep their values between play sessions
- These attributes reset them. Code in
External/DomainReloadHelper (Polis.Core.External.DomainReloadHelper), editor only
- Becomes obsolete once we move to Unity with CoreCLR
Usage
[ClearOnReload] - resets a static field, property or event when entering play mode and again when going back to edit mode
[ExecuteOnReload] - static method called at the same moment
- On a generic type every closed type in use is reset
[ClearOnReload]
private static Foo _instance;
[ClearOnReload(Value = 1)]
private static int _count;
[ClearOnReload(NewInstance = true)]
private static readonly List<Foo> CACHE = new();
- In-app restart (builds too) has its own attributes
[ClearOnAppRestart] / [ExecuteOnAppRestart], see Managers & Services
Gotchas
- Every static that holds state needs one of them, otherwise the second play starts with old data