Skip to content

EntityPrefab.AddChildPrefab(EntityPrefab, Action) Method

Definition

Namespace: Brine2D.ECS

Adds a child prefab that will be instantiated and parented to the root entity each time this prefab is instantiated.

C#
public Brine2D.ECS.EntityPrefab AddChildPrefab(Brine2D.ECS.EntityPrefab childPrefab, System.Action<Brine2D.ECS.Entity>? configure=null);

Parameters

childPrefab EntityPrefab

The prefab to instantiate as a child.

configure System.Action<Entity>

Optional action invoked on the instantiated child entity after all its components and behaviors have been applied, allowing per-instantiation overrides \(e\.g\., local offset\).

Returns

EntityPrefab

Exceptions

System.ArgumentNullException
Thrown when childPrefab is null.

System.ArgumentException
Thrown when adding childPrefab would create a circular reference \(e\.g\., a prefab referencing itself, directly or transitively\).

Example

C#
var enemyPrefab = new EntityPrefab("Enemy")
    .AddComponent<TransformComponent>()
    .AddChildPrefab(shadowPrefab)
    .AddChildPrefab(weaponPrefab, child => child.GetComponent<TransformComponent>()!.LocalPosition = new Vector2(16, 0));