-
Notifications
You must be signed in to change notification settings - Fork 0
SceneScriptable
Ondřej Kačírek edited this page May 3, 2025
·
1 revision
SceneScriptable
is a ScriptableObject
base class that provides hooks for scene lifecycle events in Unity. It allows derived ScriptableObjects to respond to scene initialization without requiring manual invocation from MonoBehaviours.
This class defines a centralized Initialized
event triggered after a scene loads. Any SceneScriptable
that overrides OnInitialize
and is active will be notified automatically.
- Hooks into Unity's scene load process via
RuntimeInitializeOnLoadMethod
- Enables ScriptableObjects to act as scene-aware assets
- Designed for lightweight runtime systems or managers
- A static
Initialize
method runs automatically after a scene load and fires theInitialized
event. -
SceneScriptable
instances subscribe to this event inOnEnable
and unsubscribe inOnDestroy
. - Subclasses can override
OnInitialize()
to perform custom scene-based logic.
[CreateAssetMenu(menuName = "MyGame/MySceneScriptable")]
public class MySceneData : SceneScriptable
{
protected override void OnInitialize()
{
Debug.Log("Scene initialized. MySceneData active.");
}
}
Make sure the ScriptableObject is either loaded directly or referenced by something active at runtime.