SingletonInitializer

Internal static utility that runs before the first scene loads to eagerly initialize singletons marked with InitializeOnLoad = true. Scans all Paragon assemblies for concrete types decorated with SingletonSettingsAttribute and triggers their Instance property getter, forcing lazy initialization to complete before any game code runs.

Definition

Namespace: Paragon Assembly: Paragon.dll

internal static class SingletonInitializer

Remarks

SingletonInitializer solves the ordering problem where game code might access a singleton in Awake() or Start() before the singleton has been created. By running at RuntimeInitializeLoadType.BeforeSceneLoad, it guarantees that all InitializeOnLoad singletons exist before any MonoBehaviour.Awake() is called.

Initialization Algorithm

  1. Collect all loaded assemblies whose FullName starts with "Paragon".

  2. From those assemblies, find all types that:

    • Are not abstract

    • Are not generic (open generic types like SingletonBehaviour<T> are excluded)

    • Have [SingletonSettings] applied (including inherited)

  3. For each matching type where InitializeOnLoad == true:

    • Resolve the Instance static property via reflection (BindingFlags.Public | Static | FlattenHierarchy)

    • Call GetValue(null) — this triggers the lazy initialization chain

Methods

Initialize

Runs before scene load. Scans and initializes all eligible singletons.

circle-info

This method is called automatically by Unity's runtime initialization system. It should never be called manually.

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation

See Also

Last updated