A MonoBehaviour that should only exist once and provides easy access to its instance. However, it isn't automatically created and still needs to be attached to a GameObject in the scene.
More...
|
virtual void | OnDestroy () |
| If this is the instance and it was destroyed, remove the instance registration. More...
|
|
|
static TSubclass | Instance [get] |
| Returns the sole instance of this class in the current scene. If the instance is not yet found cached, it searches for it and then caches it. More...
|
|
static TSubclass | InstanceOptional [get] |
| Returns the sole instance of this class in the current scene. If the instance is not already cached, it searches for it and then caches it. Note that if the instance is not found at all, InstanceOptional will try to find it on every call. For that reason, it is better to only call this once per script in Awake() or Start() and cache the result. More...
|
|
A MonoBehaviour that should only exist once and provides easy access to its instance. However, it isn't automatically created and still needs to be attached to a GameObject in the scene.
- Template Parameters
-
TSubclass | The subclass that extends from this class. |
§ OnDestroy()
If this is the instance and it was destroyed, remove the instance registration.
Note: This also means that you need to use
protected override void OnDestroy()
{
base.OnDestroy();
// [Your code]
}
in subclasses.
§ Instance
Returns the sole instance of this class in the current scene. If the instance is not yet found cached, it searches for it and then caches it.
§ InstanceOptional
Returns the sole instance of this class in the current scene. If the instance is not already cached, it searches for it and then caches it. Note that if the instance is not found at all, InstanceOptional will try to find it on every call. For that reason, it is better to only call this once per script in Awake() or Start() and cache the result.
The documentation for this class was generated from the following file:
- Singleton/SingletonMonoBehaviour.cs