Game.Events.HealthEvent
Assembly:
Assembly-CSharp (Assembly-CSharp.dll)
Namespace:
Game.Events
Type:
struct
Base:
System.ValueType
Implements: IComponentData, IQueryTypeParameter, IEmptySerializable
Summary:
HealthEvent is an intentionally empty/tag ECS component used to represent a "health" event in the game's entity-component-system. It contains no data payload; presence of this component on an entity signals that a health-related event has occurred and systems that react to that event should process and then remove the tag. The struct is marked with StructLayout(LayoutKind.Sequential, Size = 1) so it has non-zero size (1 byte), which helps with serialization and storage in native containers and avoids issues with zero-sized types in some low-level systems.
This type implements: - IComponentData — so it can be used as a standard ECS component/tag. - IQueryTypeParameter — enabling usage in query type parameters where appropriate. - IEmptySerializable — to cooperate with Colossal.Serialization.Entities (Cities: Skylines 2 serialization system) so the empty/tag component can be serialized/deserialized correctly for save/load or network scenarios.
Fields
- This struct has no instance fields. It acts as a marker/tag component.
{{ Markers like this are intentionally empty; the presence or absence of the component conveys the event. The StructLayout(Size = 1) attribute ensures the struct occupies 1 byte so it is handled correctly by native containers and serialization systems. }}
Properties
- This type exposes no properties.
{{ It is a plain value-type tag used only for signaling; if you need payload data attach a different component with fields. }}
Constructors
- The struct has only the default value-type constructor (implicit).
{{ You can instantiate it with new HealthEvent() when adding it as component data, but no initialization is required because it carries no state. }}
Methods
- This type defines no methods.
{{ Behavior should be implemented in systems that add/remove or query for this component. }}
Usage Example
// Create a one-off event entity with the HealthEvent tag
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var eventEntity = entityManager.CreateEntity(typeof(Game.Events.HealthEvent));
// Or add the tag to an existing entity
entityManager.AddComponentData(someEntity, new Game.Events.HealthEvent());
// System that consumes the HealthEvent and removes it after handling
public partial class HealthEventSystem : SystemBase
{
private EndSimulationEntityCommandBufferSystem _ecbSystem;
protected override void OnCreate()
{
_ecbSystem = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
}
protected override void OnUpdate()
{
var ecb = _ecbSystem.CreateCommandBuffer().AsParallelWriter();
Entities
.WithAll<Game.Events.HealthEvent>()
.ForEach((Entity entity, int entityInQueryIndex) =>
{
// Handle the health event here (e.g., apply damage, play VFX, etc.)
// Remove the tag so the event is consumed only once
ecb.RemoveComponent<Game.Events.HealthEvent>(entityInQueryIndex, entity);
})
.ScheduleParallel();
_ecbSystem.AddJobHandleForProducer(Dependency);
}
}
{{ Notes: - Use this tag for transient event signaling; ensure consuming systems remove the tag after processing. - If you need to persist event-related data across frames or between save/load, create a separate component with fields instead of relying solely on this empty tag. - Implementing IEmptySerializable ensures compatibility with Cities: Skylines 2 serialization infrastructure so the tag can be saved/loaded without issues. }}