Skip to content

Game.Prefabs.LifePathEvent

Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
Represents a prefab component used to configure a "life path" trigger event for the game's entity/prefab system. This component exposes the event type and whether the event should create a "chirp" (a transient entity/notification). At LateInitialize time it gathers archetype components from all child components, augments that set with runtime bookkeeping components (Created, Updated, Chirp, ChirpEntity, PrefabRef), creates an Entity archetype for chirp entities and writes a LifePathEventData component onto the prefab entity with the configured values.


Fields

  • public LifePathEventType m_EventType
    Holds the specific life-path event type (an enum defined elsewhere). This value is copied into the LifePathEventData when LateInitialize runs so runtime systems know which event this prefab represents.

  • public bool m_IsChirp
    If true, a "chirp" archetype will be created and referenced in the LifePathEventData for producing transient chirp entities. The value is propagated into LifePathEventData during LateInitialize.

Properties

  • None declared on this type. All data is exposed via public fields and the component lifecycle overrides.

Constructors

  • public LifePathEvent()
    Default parameterless constructor (implicit). Typical usage relies on Unity/engine serialization; no custom construction logic is present.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the runtime component type required on the prefab entity itself: LifePathEventData (ReadWrite). This informs the prefab-instantiation pipeline which component data to attach to instantiated entities representing this prefab.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds component types that should be part of created archetypes for entities spawned from this prefab: Game.Triggers.LifePathEvent and PrefabRef (both ReadWrite). Child components may also add their own archetype components; this method contributes the LifePath event–specific parts.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Performs final prefab initialization after all child components are available:

  • Collects all child ComponentBase instances.
  • Requests each child to add its archetype components into a HashSet.
  • Augments that set with runtime bookkeeping components: Created, Updated, Game.Triggers.Chirp, ChirpEntity, and PrefabRef.
  • Creates an EntityArchetype from the aggregated component types via entityManager.CreateArchetype(...) (using PrefabUtils.ToArray(hashSet) to convert the set).
  • Constructs a LifePathEventData struct, fills its m_ChirpArchetype with the created archetype, m_IsChirp from this component, and m_EventType from this component.
  • Writes the populated LifePathEventData into the prefab entity with entityManager.SetComponentData(entity, componentData). This method ties together prefab-time configuration (fields on this ComponentBase) with runtime ECS archetypes and data.

Notes and dependencies: - Relies on types: LifePathEventData, Game.Triggers.LifePathEvent, PrefabRef, Created, Updated, Game.Triggers.Chirp, ChirpEntity, and helper PrefabUtils. - Uses Unity.Entities API: EntityManager, Entity, ComponentType, CreateArchetype, SetComponentData. - The created chirp archetype is intended for short-lived "chirp" entities produced at runtime by the trigger system.

Usage Example

// This example demonstrates how LateInitialize sets up the runtime data.
// Typically you do not need to call this manually; the prefab system calls it.
// But you can inspect or tweak the LifePathEventData after initialization.

[Preserve]
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
    base.LateInitialize(entityManager, entity);

    // After base initialization, you can read/modify the generated LifePathEventData:
    var data = entityManager.GetComponentData<LifePathEventData>(entity);
    // Example: force this prefab to produce chirps at runtime
    data.m_IsChirp = true;
    data.m_EventType = LifePathEventType.YourDesiredType;
    entityManager.SetComponentData(entity, data);
}