Skip to main content

DontDestroyOnLoad

A class in Root.Township, the global namespace.

Keeps an object alive across scene loads, allowing only one per identifier; later duplicates destroy themselves.

Constructors​

MemberWhat it is
DontDestroyOnLoad()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
protected string identifierKey that decides which objects count as duplicates.
1 private and internal field
MemberWhat it is
private static Dictionary<string, DontDestroyOnLoad> identifiersStatic map from identifier to the surviving instance.

Properties​

MemberWhat it is
bool IsOfficial { get; private set; }True on the instance that registered and survived, false on a duplicate.

Methods​

MemberWhat it is
protected virtual void Awake()Destroys this object if another live one has the same identifier, otherwise registers it and marks it don't-destroy-on-load.