Class AssemblyUtil
Provides utilities for detecting and reacting to Unity Editor assembly reload events. Tracks whether an assembly reload is currently in progress and exposes events that systems can subscribe to in order to save and restore transient state across domain reloads.
Inherited Members
Namespace: Scylla.Core.Util
Assembly: ScyllaCore.dll
Syntax
public static class AssemblyUtil
Remarks
Assembly reloads occur in the Unity Editor whenever scripts are recompiled, a package is imported, or the Editor's domain is otherwise refreshed. During a reload all non-serialized in-memory state (static fields, runtime objects, etc.) is destroyed and must be re-initialized after the reload completes.
The Scylla Core editor assembly forwards AssemblyReloadEvents to this class. The
subscription lives there, not here, because Scylla ships this assembly compiled without
UNITY_EDITOR, and the same binary runs in the Editor of a project that installed it
as a package. A subscription made here under #if UNITY_EDITOR would never exist in
such a project.
Outside the Editor, IsReloading always returns false,
ReloadCount always returns 0, and the events are never raised.
Properties
IsReloading
Gets a value indicating whether an assembly domain reload is currently in progress.
Returns true from the moment the before-reload callback fires until the
after-reload callback completes. Always returns false outside the Editor.
Declaration
public static bool IsReloading { get; }
Property Value
| Type | Description |
|---|---|
| bool |
ReloadCount
Gets the number of assembly reloads completed in the current domain. The counter is
incremented each time AssemblyReloadEvents.afterAssemblyReload fires, and it is
a static field, so a domain reload resets it: after a script reload it reads 1, not the
number of reloads since the Editor started. Always returns 0 outside the
Editor.
Declaration
public static int ReloadCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
Events
OnAfterReload
Invoked after an assembly domain reload has finished and all types have been
re-initialized. Subscribe to this event to restore cached state, re-register
callbacks, or reinitialize Editor-only systems.
Exceptions thrown by subscribers are caught and logged via Debug.LogException
so that a single faulting subscriber does not prevent subsequent handlers from running.
Declaration
public static event Action OnAfterReload
Event Type
| Type | Description |
|---|---|
| Action |
Remarks
Raised only in the Unity Editor. Subscribing in a player build is harmless and never fires.
OnBeforeReload
Invoked just before an assembly domain reload begins. Subscribe to this event to
serialize or cache any transient Editor state that must survive the reload.
Exceptions thrown by subscribers are caught and logged via Debug.LogException
so that a single faulting subscriber does not prevent subsequent handlers from running.
Declaration
public static event Action OnBeforeReload
Event Type
| Type | Description |
|---|---|
| Action |
Remarks
Raised only in the Unity Editor. Subscribing in a player build is harmless and never fires.