Game.Events.TrafficAccident
Assembly: Assembly-CSharp
Namespace: Game.Events
Type: struct
Base: System.ValueType
Summary:
TrafficAccident is an empty marker (tag) component used in the ECS to mark entities that are involved in a traffic accident. It is laid out with a fixed size of 1 byte to avoid zero-sized type issues when serialized. The type implements Unity.Entities.IComponentData so it can be attached to entities, Unity.Entities.IQueryTypeParameter so it can be used directly in queries, and Colossal.Serialization.Entities.IEmptySerializable to participate in the game's serialization subsystem.
Fields
- (none)
This struct contains no instance fields; it is intentionally empty and acts purely as a tag/marker component. The type does carry the attribute [StructLayout(LayoutKind.Sequential, Size = 1)] to force a 1-byte size for serialization and layout reasons.
Properties
- (none)
There are no properties on this type.
Constructors
- default (implicit) parameterless constructor
As a value type, TrafficAccident has an implicit parameterless constructor. No explicit constructors are defined.
Methods
- (none)
No methods are defined; the type only serves as a marker and relies on ECS systems to read presence/absence.
Remarks
- Interfaces implemented:
- Unity.Entities.IComponentData — marks this as an ECS component.
- Unity.Entities.IQueryTypeParameter — allows the type to be used directly in EntityQuery/Entities.ForEach filters.
- Colossal.Serialization.Entities.IEmptySerializable — indicates the type participates in the game's custom serialization for empty components.
- Attribute:
- [StructLayout(LayoutKind.Sequential, Size = 1)] — ensures the type occupies 1 byte in memory/serialization rather than being treated as a zero-sized type.
Usage Example
using Unity.Entities;
using Game.Events;
public partial class TrafficAccidentSystem : SystemBase
{
protected override void OnUpdate()
{
// Example: process all entities that currently have the TrafficAccident tag
Entities
.WithAll<TrafficAccident>()
.ForEach((Entity entity, in SomeOtherComponent state) =>
{
// handle accident logic for this entity
})
.Schedule();
}
}
// Elsewhere, adding/removing the tag to an entity:
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity someEntity = /* obtain or create entity */;
// Add the traffic accident tag
entityManager.AddComponent<TrafficAccident>(someEntity);
// Remove the traffic accident tag
entityManager.RemoveComponent<TrafficAccident>(someEntity);
This component is intended for lightweight tagging; systems should check for the presence or absence of this component to drive accident-related behavior (cleanup, effects, rerouting, etc.).