SceneScriptable - BluePixelDev/utilkit GitHub Wiki
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.
Overview
This class defines a centralized Initialized
event triggered after a scene loads. Any SceneScriptable
that overrides OnInitialize
and is active will be notified automatically.
Key Features
- Hooks into Unity's scene load process via
RuntimeInitializeOnLoadMethod
- Enables ScriptableObjects to act as scene-aware assets
- Designed for lightweight runtime systems or managers
How It Works
- 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.
Usage Example
[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.