Skip to main content
Namespace: Molca
File: Packages/com.molca.core/Runtime/RuntimeManager.cs

When to use

RuntimeManager is the single bootstrap entry point for every Molca-based project. You interact with it when:
  • Waiting for initialization before accessing any service or subsystem (always call await RuntimeManager.WaitForInitialization() before resolving services).
  • Registering or resolving services through the built-in DI container (GetService<T>, RegisterService<T>).
  • Injecting dependencies into runtime-created objects that missed the automatic scene injection pass.
  • Creating factory-produced instances with constructor + field injection via CreateWithInjection<T>.

Bootstrap

After scene load, static initialization loads Molca Project Settings, instantiates the configured RuntimeManager prefab, calls DontDestroyOnLoad, then runs async InitializeAsync: GlobalSettings load, subsystem discovery, service registration, scene-wide dependency injection, then IsReady.

Using from code

Service API

Prefer GetService<T>() / TryGetService<T>(). For RuntimeSubsystem types, GetSubsystem<T>() still resolves the same instance but is labeled legacy in source comments.

Troubleshooting

  • Services/subsystems are null in Start or Awake: call await RuntimeManager.WaitForInitialization() before resolving. [Inject] fields are null until the injection pass completes.
  • MolcaProjectSettings failed to load: ensure a MolcaProjectSettings asset exists under Resources/ and the RuntimeManager prefab field is assigned.
  • Multiple instances of subsystem type warning: only one enabled component of each RuntimeSubsystem type should exist on the prefab. Duplicates are automatically removed.
  • Dynamically created objects have null [Inject] fields: call RuntimeManager.InjectInto(component) after Instantiate / AddComponent — the automatic scene pass only runs once during init.
  • Circular dependency detected: two services depend on each other during resolution. Refactor one to use lazy resolution or event-based decoupling.

Unity Editor

Runtime Manager Prefab

RuntimeManager prefab instance (DontDestroyOnLoad) in Hierarchy and Inspector