Skip to content

Game.LaneDeteriorationData

Assembly:
Assembly-CSharp

Namespace:
Game.Prefabs

Type:
struct

Base:
Implements Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter

Summary:
LaneDeteriorationData is a simple ECS component intended to hold per-lane deterioration modifiers used by lane deterioration or maintenance systems in Cities: Skylines 2 mods. It contains two float factors that influence how quickly a lane degrades based on traffic load and elapsed time. The struct is a plain data container (POD) and is safe to use in jobs and parallel systems.


Fields

  • public float m_TrafficFactor
    Multiplier applied to a metric derived from traffic (e.g., vehicle count, congestion). Higher values increase the contribution of traffic to lane deterioration. Expected to be >= 0; the scale and interpretation are defined by the consuming system.

  • public float m_TimeFactor
    Multiplier applied to elapsed time (e.g., seconds, game days) to calculate time-driven deterioration. Higher values increase the rate of deterioration over time. Expected to be >= 0; the time units depend on the system that uses this value (commonly seconds or scaled in-game time).

Properties

  • This type defines no properties.

Constructors

  • public LaneDeteriorationData() (implicit parameterless struct constructor)
    Structs in C# get an implicit default constructor setting numeric fields to 0. You can also initialize the fields via an object initializer:
new LaneDeteriorationData { m_TrafficFactor = 0.5f, m_TimeFactor = 1.0f }

Methods

  • This type declares no methods.

Usage Example

Creating an entity with the component and setting values, and a simple SystemBase example that reads/modifies the component:

using Unity.Entities;
using Game.Prefabs;

// Creating an entity with default values
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
var archetype = em.CreateArchetype(typeof(LaneDeteriorationData));
var entity = em.CreateEntity(archetype);
em.SetComponentData(entity, new LaneDeteriorationData { m_TrafficFactor = 0.4f, m_TimeFactor = 0.2f });

// Simple system that uses the component
public partial class LaneDeteriorationSystem : SystemBase
{
    protected override void OnUpdate()
    {
        float dt = Time.DeltaTime;
        Entities.ForEach((ref LaneDeteriorationData lane /*, in TrafficState traffic */) =>
        {
            // Example usage: combine traffic and time factors to compute a deterioration delta.
            // Replace the pseudo traffic value with actual traffic data from another component.
            float exampleTrafficMetric = 10f;
            float deteriorationDelta = lane.m_TrafficFactor * exampleTrafficMetric * dt +
                                       lane.m_TimeFactor * dt;
            // Apply deteriorationDelta to lane health / state in your system.
        }).ScheduleParallel();
    }
}