Skip to main content
File: Assets/_Molca/_Core/Runtime/RuntimeSubsystem.cs
Base for: ModalManager, ScenarioSessionManager, VRFadeManager, GameManager, TourSubsystem, etc.

When to use

Subclass RuntimeSubsystem when you need a cross-scene service that:
  • Must initialize before gameplay code runs (controlled by InitializationPriority).
  • Should be registered in the DI container automatically for [Inject] and GetService<T> resolution.
  • Needs lifecycle hooks (initialize → activate → deactivate → shutdown) tied to RuntimeManager.
For components that don’t need cross-scene persistence, use a regular MonoBehaviour with [Inject] instead.

Lifecycle

  1. Initialize(Action<IRuntimeSubsystem> finishCallback) — must invoke the callback when finished.
  2. Activate() / Deactivate() — default toggles isActive.
  3. Shutdown() — default calls Deactivate().

RuntimeMode

Serialized flags can restrict a subsystem to Editor and/or Player so tooling components do not run in builds.

InitializationPriority

RuntimeManager sorts subsystems in descending order: higher numeric InitializationPriority runs first.

Placement

Add each subsystem once as an enabled child component on the RuntimeManager prefab. Duplicate component types are detected and duplicates removed with a warning.

Code

using System;
using UnityEngine;
using Molca;

public class MyTelemetrySubsystem : RuntimeSubsystem
{
    public override void Initialize(Action<IRuntimeSubsystem> finishCallback)
    {
        // Register providers, start sockets, etc.
        Activate();
        finishCallback?.Invoke(this);
    }

    public override void Shutdown()
    {
        // Tear down before base / RuntimeManager clears services
        base.Shutdown();
    }
}
Attach this once on the RuntimeManager prefab and set InitializationPriority so it runs before/after dependents.

Troubleshooting

  • Subsystem never initializes: ensure finishCallback is invoked — RuntimeManager awaits it with a 20-second timeout.
  • Subsystem runs in builds but shouldn’t: set RuntimeMode to Editor on the component to exclude it from player builds.
  • GetSubsystem<T>() returns null: the subsystem must be an enabled child of the RuntimeManager prefab (or registered via RuntimeManager.RegisterSubsystem).

Unity Editor

Runtime Subsystems On Prefab