Skip to main content
Folder: Assets/_Molca/_Core/ReferenceSystem/

When to use

Use the reference system when you need stable, late-bound connections between objects across scenes or prefab boundaries:
  • Cross-scene references — link a step in one scene to an interaction in another without hard SerializeField references.
  • Addressable/dynamic content — resolve references after objects are loaded at runtime.
  • VR step → interaction wiringValveStep finds its ValveInteraction via SceneObjectReference rather than a direct drag-and-drop link.
TypeRole
ReferenceManagerRegistry of IReferenceable instances
ReferenceableComponentAssigns stable Ref Id + type string on a GameObject
SceneObjectReferenceSerialized id → Resolve<T>() after startup
Step implements IReferenceable<Step> with RefType "Step".

Typical pattern

  1. Target: add ReferenceableComponent, set unique Ref Id.
  2. Consumer: SceneObjectReference field in Inspector, then Resolve<T>() after RuntimeManager.WaitForInitialization().

Code

using Molca;
using Molca.ReferenceSystem;
using Molca.Sequence;
using UnityEngine;

public class ValveTask : MonoBehaviour
{
    [SerializeField] private SceneObjectReference targetStep;

    private async void Start()
    {
        await RuntimeManager.WaitForInitialization();
        var step = await targetStep.ResolveAsync<Step>();
        if (step != null)
            Debug.Log($"Linked step: {step.DisplayName}");
    }
}
Prefer ResolveAsync<T>() so registration has finished; synchronous Resolve<T>() is fine once RuntimeManager.IsReady.

Troubleshooting

  • Resolve<T>() returns null: the target ReferenceableComponent may not be registered yet. Use ResolveAsync<T>() after RuntimeManager.WaitForInitialization() instead.
  • Duplicate Ref Ids: each ReferenceableComponent must have a unique RefId within its RefType. Duplicates cause the first registration to win; later ones are silently ignored.
  • Reference breaks after scene reload: ReferenceManager clears registrations on scene changes. Re-resolve references in OnEnable or Start of the new scene.

Unity Editor

Show SceneObjectReference drawer and/or ReferenceableComponent on a valve or step object.

Unity Inspector showing SceneObjectReference and ReferenceableComponent