Skip to content

Game.HealthEvent

Assembly:
Assembly-CSharp (game code)

Namespace:
Game.Prefabs

Type:
class

Base:
ComponentBase

Summary:
HealthEvent is a prefab component used to configure and provide data for health-related events (Game.Events.HealthEvent) in the ECS world. It exposes editor-configurable fields that determine the target type, specific health event type, occurrence and transport probabilities, and whether tracking is required. The component registers the necessary ECS component types and writes a HealthEventData component to the entity during initialization.


Fields

  • public EventTargetType m_RandomTargetType = EventTargetType.Citizen
    Specifies which kind of target should be chosen for the event when a random target is required. Default is Citizen.

  • public HealthEventType m_HealthEventType
    The specific health event subtype (enum) that this prefab represents. Determines the behavior handled by the game event system.

  • public Bounds1 m_OccurenceProbability = new Bounds1(0f, 50f)
    A Bounds1 range representing the occurrence probability (min/max) for the event. Default range is 0 to 50.

  • public Bounds1 m_TransportProbability = new Bounds1(0f, 100f)
    A Bounds1 range representing the probability related to transport (for example, probability that an affected unit is transported). Default range is 0 to 100.

  • public bool m_RequireTracking = true
    If true, the event requires tracking of the target (for instance to follow the affected citizen/vehicle). Default is true.

Properties

  • None declared on this prefab component. The class exposes configuration via public fields and implements component registration/initialization via overridden methods.

Constructors

  • public HealthEvent()
    Default (parameterless) constructor provided by C#. The class relies on field initializers for default values and does not declare an explicit constructor.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the prefab's runtime component requirement: it registers HealthEventData (read/write) to the set of components required on the instantiated entity. This ensures the entity will contain the data structure populated in Initialize.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds the archetype-level components needed for entities created from this prefab: Game.Events.HealthEvent and TargetElement (both read/write). This controls the ECS archetype composition.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called when the prefab is instantiated. Creates and populates a HealthEventData instance using the prefab fields:

  • m_RandomTargetType -> m_RandomTargetType
  • m_HealthEventType -> m_HealthEventType
  • m_OccurenceProbability -> m_OccurenceProbability
  • m_TransportProbability -> m_TransportProbability
  • m_RequireTracking -> m_RequireTracking Then writes this data into the entity via entityManager.SetComponentData(entity, componentData).

Usage Example

// Example showing how the prefab's Initialize populates HealthEventData on the entity.
// (This mirrors what HealthEvent.Initialize already does inside the prefab implementation.)
public void ExampleInitialize(EntityManager entityManager, Entity entity, HealthEvent prefab)
{
    var data = new HealthEventData {
        m_RandomTargetType = prefab.m_RandomTargetType,
        m_HealthEventType = prefab.m_HealthEventType,
        m_OccurenceProbability = prefab.m_OccurenceProbability,
        m_TransportProbability = prefab.m_TransportProbability,
        m_RequireTracking = prefab.m_RequireTracking
    };
    entityManager.SetComponentData(entity, data);
}

Notes / Tips: - The class is decorated with [ComponentMenu("Events/", typeof(EventPrefab))], so it will appear under the Events menu in the component/prefab editor tooling. - The ECS components referenced (HealthEventData, Game.Events.HealthEvent, TargetElement) must exist in the assembly and match the expected fields/types for proper runtime behavior. - Adjust the Bounds1 ranges and m_RequireTracking in the prefab to tune how often events occur and whether they require tracking for your mod.