Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs-unity.molca.id/llms.txt

Use this file to discover all available pages before exploring further.

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.

Using from 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.

API Reference

MethodSignatureDescription
Initializeabstract void Initialize(Action<IRuntimeSubsystem> finishCallback)Called by RuntimeManager during bootstrap. Must invoke finishCallback when initialization is complete. RuntimeManager waits up to 20 seconds for the callback.
Shutdownvirtual void Shutdown()Called when RuntimeManager is destroyed or application quits. Default implementation calls Deactivate(). Override to clean up resources before base shutdown.
Activatevirtual void Activate()Enables the subsystem. Default implementation sets isActive = true. Called after successful initialization.
Deactivatevirtual void Deactivate()Disables the subsystem. Default implementation sets isActive = false. Called during shutdown or when subsystem needs to pause.
OnApplicationPausevirtual void OnApplicationPause(bool pauseStatus)Unity lifecycle callback forwarded from RuntimeManager. Override to handle application pause/resume events (mobile backgrounding, focus loss).
OnApplicationQuitvirtual void OnApplicationQuit()Unity lifecycle callback forwarded from RuntimeManager. Override to perform cleanup before application termination. Called before Shutdown().
InitializationPriorityint InitializationPriority { get; set; }Determines initialization order. Higher values initialize first (descending sort). Set in Inspector or constructor.
RuntimeModeRuntimeMode RuntimeMode { get; set; }Flags controlling whether subsystem runs in Editor and/or Player builds. Use to exclude tooling subsystems from runtime builds.
isActivebool isActive { get; protected set; }Current activation state. Set by Activate() and Deactivate(). Check before performing subsystem operations.

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