Skip to content

Game.TrafficAccidentData

Assembly:
{{ Likely part of the game's runtime assembly where Game.* types live (e.g., Game.dll). If you're building a mod, this type will be compiled into your mod's assembly. }}

Namespace: Game.Prefabs

Type: struct

Base: IComponentData, IQueryTypeParameter

Summary:
{{ TrafficAccidentData is a small ECS component that describes configuration for a traffic-accident event/prefab in Cities: Skylines 2. It stores which targets/sites the accident may occur at, what kind of accident it is, and the probability that the accident occurs. The struct is plain data (value type) intended to be attached to an Entity as part of the Unity.Entities (DOTS) workflow. Note: the field m_OccurenceProbability is misspelled in the source (should be "Occurrence"). }}


Fields

  • public EventTargetType m_RandomSiteType
    {{ Defines the type of site/location that should be chosen at random for the accident to occur. Typical values come from the EventTargetType enum (for example: Road, Intersection, Building, etc.). This tells the system where to look for candidate sites. }}

  • public EventTargetType m_SubjectType
    {{ Defines what the subject of the event is (for example vehicle, pedestrian, or another target type depending on the EventTargetType enum). The subject is the entity/group that is considered "involved" in the accident. }}

  • public TrafficAccidentType m_AccidentType
    {{ Specifies the kind of traffic accident to spawn or simulate (e.g., collision, pile-up, fire, breakdown). Values are defined in the TrafficAccidentType enum. The downstream spawning/system logic will choose appropriate visuals/behaviour based on this value. }}

  • public float m_OccurenceProbability
    {{ A probability value (usually between 0 and 1) that indicates how likely this configured accident is to occur when the game/system evaluates possible events. Note the field name is misspelled ("Occurence"); treat it as the canonical name when setting or reading the component. }}

Properties

{{ This type does not declare any properties; it only exposes the public fields listed above. As a plain IComponentData struct it should be treated as a POD (plain-old-data) container. }}

Constructors

  • public TrafficAccidentData()
    {{ The implicit default constructor initializes numeric fields to 0 and enum fields to their default value (usually the first enum value). If you need non-default initial values, construct the struct with an object initializer or assign its fields explicitly before adding it to an entity. }}

Methods

{{ There are no methods defined on this struct. It is a pure data container used with ECS systems and queries. }}

Usage Example

// Example: create an entity with a TrafficAccidentData component and set its fields.
// Requires Unity.Entities and appropriate using directives.

public void CreateTrafficAccidentPrefab(EntityManager entityManager)
{
    // Create an archetype that includes the TrafficAccidentData component
    var archetype = entityManager.CreateArchetype(typeof(TrafficAccidentData));

    // Create an entity from that archetype
    var entity = entityManager.CreateEntity(archetype);

    // Set the component data (adjust enum values to available ones)
    var accident = new TrafficAccidentData
    {
        m_RandomSiteType = EventTargetType.Road,
        m_SubjectType = EventTargetType.Vehicle,
        m_AccidentType = TrafficAccidentType.Collision,
        m_OccurenceProbability = 0.05f // 5% chance
    };

    entityManager.SetComponentData(entity, accident);
}

{{ Additional notes: - Because this is an IComponentData, prefer copying and setting the entire struct rather than mutating individual fields on shared instances for clarity. - The IQueryTypeParameter marker indicates this type can be used as a parameter in queries or query-like APIs; consult the modding/DOTS docs for patterns to use it in EntityQuery or SystemBase queries. - Validate probability values (0..1) in your systems before interpreting them. - Watch for the misspelling of m_OccurenceProbability when interacting with serialized/prefab data or reflection-based code. }}