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.

Namespace: Molca
File: Assets/_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

await RuntimeManager.WaitForInitialization();

Service API

Prefer GetService<T>() / TryGetService<T>(). For RuntimeSubsystem types, GetSubsystem<T>() still resolves the same instance but is labeled legacy in source comments.
MethodSignatureDescription
WaitForInitializationstatic async Awaitable WaitForInitialization()Blocks until IsReady is true
GetService<T>static T GetService<T>() where T : classResolve a registered service; returns null if not found
TryGetService<T>static bool TryGetService<T>(out T service)Try-pattern resolution; returns true if found
HasService<T>static bool HasService<T>()Check if a service type is registered
RegisterService<T>static void RegisterService<T>(T instance)Register a singleton service instance
BindService<TI,TImpl>static void BindService<TI, TImpl>()Lazy singleton — created on first request
RegisterFactory<T>static void RegisterFactory<T>(Func<T> factory)Transient — factory called each resolution
GetSubsystem<T>static T GetSubsystem<T>() where T : RuntimeSubsystemLegacy; delegates to GetService<T>
InjectDependenciesstatic void InjectDependencies(object target)Inject [Inject] fields/properties on any object
InjectIntostatic void InjectInto(MonoBehaviour target)Inject into a specific runtime-created MonoBehaviour
CreateWithInjection<T>static T CreateWithInjection<T>() where T : classConstruct + inject fields/properties
RegisterSubsystemstatic async void RegisterSubsystem(RuntimeSubsystem s)Register an external subsystem after init
DeregisterSubsystemstatic void DeregisterSubsystem(RuntimeSubsystem s)Remove a previously registered subsystem
RunCoroutinestatic Coroutine RunCoroutine(IEnumerator e)Start a coroutine on the RuntimeManager instance

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