ComponentHandle<T>
A handle to a component being authored on a GameObject (via NodeHandle.Component). Set serialized fields either by serialized property path (c.Set("m_Mass", 5f)) or by a typed member selector (c.Set(r => r.mass, 5f)).
public sealed partial class ComponentHandle<T>T
Compile-time scaffolding only — SceneBuilder parses the source text to build the scene, so these methods return handles for chaining but perform no work at runtime.
Members
Setmethod4 overloads
public ComponentHandle<T> Set(string serializedPath, object value)Set a serialized field by its serialized property path (e.g. "m_Mass").
public ComponentHandle<T> Set<TValue>(Func<T, TValue> selector, TValue value)Set a field by typed member selector (e.g. r => r.mass).
public ComponentHandle<T> Set<TValue>(Func<T, TValue> selector, AssetReference asset)Set an asset-reference field by typed member selector, e.g. c.Set(r => r.sharedMaterial, Asset("Assets/Materials/Red.mat")). The selector's return type is the asset type; the value is the AssetReference factory result.
public ComponentHandle<T> Set<TValue>(Func<T, TValue> selector, SceneObjectHandle target)Set a cross-object-reference field by typed member selector, e.g. c.Set(r => r.target, door). The target is any scene object handle — a GameObject or a prefab instance root. Pass NodeHandle.None to clear the slot.
OnClickmethod6 overloads
public ComponentHandle<T> OnClick<TTarget>(ComponentRef<TTarget> target, Action<TTarget> method)Wire a persistent listener onto this component's OnClick UnityEvent (m_OnClick): when it fires, call method on target. The method is a typed lambda on the target component, so a method it does not have fails to compile. The lambda's own call carries the static argument, if any (e.g. x => x.SetLevel(3)); a zero-argument call wires a void listener.
public ComponentHandle<T> OnClick<TTarget>(ComponentRef<TTarget> target, Action<TTarget> method, UnityEngine.Events.UnityEventCallState callState)Wire a persistent listener onto this component's OnClick UnityEvent, with an explicit callState governing whether it fires in edit mode, play mode, or both. Omitting this argument defaults to RuntimeOnly.
public ComponentHandle<T> OnClick<TTarget>(AssetReference target, Action<TTarget> method)Wire a persistent listener whose target is a project asset (resolved through the typed asset catalog, e.g. Assets.Prefabs.Speakers.Speaker) rather than a scene reference. TTarget is not inferable from an asset reference, so the call site supplies it explicitly (e.g. b.OnClick<AudioSource>(Assets.Prefabs.Speaker, a => a.Play())).
public ComponentHandle<T> OnClick<TTarget>(AssetReference target, Action<TTarget> method, UnityEngine.Events.UnityEventCallState callState)The asset-target form of OnClick with an explicit callState.
public ComponentHandle<T> OnClick(SceneObjectHandle target, Action<UnityEngine.GameObject> method)Wire a persistent listener whose target is a GameObject (a scene node, not one of its components) — the shape a Button.onClick => GameObject.SetActive(false) wiring takes.
public ComponentHandle<T> OnClick(SceneObjectHandle target, Action<UnityEngine.GameObject> method, UnityEngine.Events.UnityEventCallState callState)The GameObject-target form of OnClick with an explicit callState.
OnEventmethod6 overloads
public ComponentHandle<T> OnEvent<TEvent, TTarget>(Func<T, TEvent> unityEvent, ComponentRef<TTarget> target, Action<TTarget> method)Wire a persistent listener onto an arbitrary UnityEvent-typed field selected by unityEvent (e.g. b.OnEvent(x => x.onValueChanged, target, t => t.Method())), rather than the fixed OnClick shortcut. TEvent is unconstrained, so any UnityEvent-typed field on T is authorable this way.
public ComponentHandle<T> OnEvent<TEvent, TTarget>(Func<T, TEvent> unityEvent, ComponentRef<TTarget> target, Action<TTarget> method, UnityEngine.Events.UnityEventCallState callState)The component-target form of OnEvent with an explicit callState.
public ComponentHandle<T> OnEvent<TEvent, TTarget>(Func<T, TEvent> unityEvent, AssetReference target, Action<TTarget> method)The asset-target form of OnEvent: wires the selected event field to a method on an asset reference rather than a scene component.
public ComponentHandle<T> OnEvent<TEvent>(Func<T, TEvent> unityEvent, SceneObjectHandle target, Action<UnityEngine.GameObject> method)The GameObject-target form of OnEvent: wires the selected event field to a method on the target GameObject itself (e.g. SetActive).
public ComponentHandle<T> OnEvent<TArg, TTarget>(Func<T, UnityEngine.Events.UnityEvent<TArg>> unityEvent, ComponentRef<TTarget> target, Func<TTarget, Action<TArg>> method, bool dynamic)Wire a "dynamic" persistent listener: the argument the event fires with is passed straight through to method at runtime, rather than a static value baked in at authoring time. method is a method GROUP on the target (e.g. h => h.SetValue, not h => h.SetValue(...)) whose parameter type is TArg — the selected event's own generic argument.
public ComponentHandle<T> OnEvent<TArg0, TArg1, TTarget>(Func<T, UnityEngine.Events.UnityEvent<TArg0, TArg1>> unityEvent, ComponentRef<TTarget> target, Func<TTarget, Action<TArg0, TArg1>> method, bool dynamic)The two-argument-event form of OnEvent.
SetRefmethod
public ComponentHandle<T> SetRef<TField>(Func<T, TField> selector, TField value)Set a [SerializeReference] polymorphic field by typed member selector, e.g. c.SetRef(r => r.strategy, new Aggressive { range = 5f }). The selector fixes TField to the field's declared interface/abstract/base type; any assignable concrete instance, or null to clear the reference, may be passed.