Skip to content

Game.Events.InvolvedInAccident

Assembly: Game
Namespace: Game.Events

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary: Component used by the game's ECS to mark an entity as being involved in an accident. Holds a reference to the accident event entity, a severity value, and the simulation frame when the involvement occurred. Implements custom serialization with version-aware deserialization for backward compatibility.


Fields

  • public Entity m_Event
    Holds the Entity that represents the accident event this entity is involved in.

  • public float m_Severity
    A float representing the severity of the involvement (e.g., damage or impact magnitude).

  • public uint m_InvolvedFrame
    Simulation frame at which the entity became involved in the accident. Note: this value is conditionally read during deserialization depending on the saved-game version.

Properties

  • This type defines no properties.

Constructors

  • public InvolvedInAccident(Entity _event, float severity, uint simulationFrame)
    Initializes a new instance with the accident event Entity, severity, and the simulation frame when involvement occurred.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component data to the provided writer in this order: m_Event, m_Severity, m_InvolvedFrame. Used when saving the component to the save stream.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads component data from the provided reader. Reads m_Event and m_Severity unconditionally. The m_InvolvedFrame is read only if reader.context.version >= Version.accidentInvolvedFrame, preserving backward compatibility with older save formats.

Additional notes: - The serialization order must match between Serialize and Deserialize. - The code uses ref locals to read directly into the struct fields during deserialization. - The Version.accidentInvolvedFrame check ensures older saves that lack the involved-frame value can still be loaded.

Usage Example

// Example: attach InvolvedInAccident to an entity that was involved in an accident
Entity eventEntity = /* the accident event entity */;
Entity involvedEntity = /* the entity being marked as involved */;
float severity = 0.75f;
uint currentFrame = SimulationManager.instance.m_currentFrame; // example source for frame

var involvedComp = new Game.Events.InvolvedInAccident(eventEntity, severity, currentFrame);
entityManager.AddComponentData(involvedEntity, involvedComp);