SingletonNetworkBehaviour
Abstract generic singleton base class for network behaviours that need exactly one authoritative instance in the networked scene. Combines the SingletonBehaviour pattern (find → load → create) with automatic NetworkObject.Spawn() on Start().
Definition
Namespace: Paragon.Core.Network Assembly: Paragon.dll
[SingletonSettings]
public abstract class SingletonNetworkBehaviour<T> : ParagonNetworkBehaviour
where T : SingletonNetworkBehaviour<T>Inheritance: NetworkBehaviour → ParagonNetworkBehaviour → SingletonNetworkBehaviour<T>
Remarks
This class mirrors the SingletonBehaviour<T> pattern used by non-networked singletons but adds network-specific behaviour:
Instance resolution follows a chain: cached instance →
FindFirstObjectByType<T>()→Resources.Load<T>(assetPath)→ create newGameObjectwith component.Auto-spawn: On
Start(), if theNetworkObjectis not already spawned, it callsNetworkObject.Spawn()automatically. This ensures the singleton is network-visible as soon as it enters the scene.DontDestroyOnLoad support via
[SingletonSettings(DontDestroyOnLoad = true)].Editor asset creation: In the editor, if an
AssetPathis configured and no prefab exists, one is automatically created inAssets/Resources/.
The class uses the curiously recurring template pattern (CRTP) — T must be the concrete subclass itself.
Play Mode only: Instance asserts that Application.isPlaying is true. Accessing the singleton outside Play Mode will trigger a Debug.Assert.
Quick Lookup
Access the singleton
MySingleton.Instance
Check debug state
MySingleton.DebugEnabled
Create a network singleton
Subclass with [SingletonSettings] (see example)
Properties
Instance (static)
Returns the singleton instance, creating or finding it if necessary.
Resolution order:
Cached
instancefieldFindFirstObjectByType<T>()in the sceneResources.Load<T>(assetPath)ifAssetPathis configuredCreate new
GameObjectwithAddComponent<T>()
DebugEnabled (static, new)
Whether debug output is enabled for the singleton instance. Shadows the instance-level property for convenient static access.
Extension Points
Optional Overrides
Awake()
Initializes the singleton. Sets instance, applies DontDestroyOnLoad and hide flags. Call base.Awake() if overriding.
Start()
Auto-spawns the NetworkObject if not already spawned. Call base.Start() if overriding.
OnDestroy()
Clears the static instance reference. Call base.OnDestroy() if overriding.
Implementation Requirements
When subclassing SingletonNetworkBehaviour<T>, you MUST:
Pass the concrete class as
T(CRTP):class MyManager : SingletonNetworkBehaviour<MyManager>Apply
[SingletonSettings]attribute (even with defaults)Ensure the prefab has a
NetworkObjectcomponent (required forSpawn()inStart())
You SHOULD:
Set
AssetPathin[SingletonSettings]if the singleton should be loadable from ResourcesSet
DontDestroyOnLoad = truefor managers that persist across scenesCall
base.Awake()andbase.Start()if overriding lifecycle methods
You SHOULD NOT:
Access
Instanceoutside of Play Mode (assertion will fire)Create multiple instances of the same singleton type (assertion will fire in
Awake())
Common Pitfalls
Missing NetworkObject component Start() calls NetworkObject.Spawn(). If the GameObject lacks a NetworkObject, this will throw a NullReferenceException. Always ensure the prefab or dynamically created object has a NetworkObject.
Duplicate singleton instances Creating two instances of the same type triggers a Debug.Assert in Awake(). Ensure only one instance exists — the resolution chain (find → load → create) handles this automatically when using Instance.
Overriding Awake/Start without calling base Forgetting base.Awake() skips singleton registration, DontDestroyOnLoad, and hide flag setup. Forgetting base.Start() skips auto-spawning on the network.
Examples
Creating a Network Singleton Manager
Accessing the Singleton
See Also
ParagonNetworkBehaviour — the base class this extends
NetworkManager — the network system entry point
Last updated