Structure behaviors
Use case
Use this contract when project logic must react to committed placement, movement, orientation, or removal of a structure.
Contract and ownership
Implement a narrow runtime behavior interface such as IGridStructurePlacedBehavior for placed, removed, or action-applied lifecycle, or derive a GridStructureBehaviorAsset for authored composition.
Behaviors observe committed state. The binding owns subscriptions and must be disposed with the state/library lifecycle. A behavior must not reinterpret a callback as permission to mutate internals.
Implementation
Excerpt — observe committed structure lifecycle callbacks. Tested using public APIs.
public sealed class StructureLifecycleLogger :
GridStructureBehaviorAsset
{
protected override void OnStructurePlaced(
GridStructurePlacedBehaviorContext context)
{
Debug.Log($"Placed {context.Instance.InstanceId}");
}
protected override void OnStructureRemoved(
GridStructureRemovedBehaviorContext context)
{
Debug.Log($"Removed {context.Structure.InstanceId}");
}
}
Prefer sending a game command or running a new action when a reaction needs mutation. Guard against feedback loops.
Registration
Add behavior assets to the corresponding structure entry in the library. Programmatic callers use
Attach(...) and Detach(...) on
GridStructureBehaviors to
own the returned IDisposable.
Verification
Validate missing definitions/behaviors while building the library. Treat callback exceptions as observer faults and report them with structure instance/definition IDs.
Tests
Assert callbacks occur only after commit, receive detached committed values, do not run for preview/rejection, and stop after binding disposal.
Related
- Structures, footprints, layers, and occupancy
- Observe committed events
- IGridStructurePlacedBehavior
- IGridStructureRemovedBehavior
- GridStructureBehaviorAsset
- GridStructureBehaviors
Done when
The behavior runs only for the intended committed lifecycle event, reports failures through diagnostics, and does not mutate board state outside the owning transaction.