1using System.Collections.Generic;
12 [DisallowMultipleComponent]
13 [DefaultExecutionOrder(-1)]
16 private static readonly Dictionary<string, Transform> instances =
new();
18 [Tooltip(
"Enable to preserve this object across scene changes.")]
20 private new bool enabled =
true;
36 if (instances.TryGetValue(
Id, out var existing))
41 if (ReferenceEquals(transform, existing))
43 Destroy(transform.gameObject);
50 instances[
Id] = transform;
51 if (transform != transform.root)
53 transform.SetParent(
null);
55 DontDestroyOnLoad(transform);
virtual string Id
The unique identifier for the object instance. It is serialized and can be viewed and modified in the...
Provides a base class for objects requiring a unique identifier, using MonoBehaviour as its foundatio...
virtual void Awake()
Initializes the component during Unity's Awake callback.
virtual void OnApplicationQuit()
Handles application shutdown.
virtual void OnDisable()
Handles the Unity disable callback.
bool IsDestroyed
Indicates whether the object has been destroyed. It becomes true if the object is explicitly destroye...
A utility component to make an object persist across different scenes in a Unity project....