Skip to content

Game.Vehicles.Blocker

Assembly: Assembly-CSharp
Namespace: Game.Vehicles

Type: struct (value type)

Base: System.ValueType, IComponentData, IQueryTypeParameter, ISerializable

Summary:
Component used by the vehicle/traffic systems to mark an entity as a "blocker". Contains a reference to the blocking entity, a blocker classification (BlockerType) and a maximum speed limit (stored as a byte). Implements custom serialization to maintain compatibility with older save formats.


Fields

  • public Entity m_Blocker
    Reference to the entity that acts as the blocker. This Entity is written/read by the component's serialization methods.

  • public BlockerType m_Type
    Classification of the blocker. Serialized as a single byte. When deserializing from pre-trafficBottlenecks versions, this field is set to BlockerType.None.

  • public byte m_MaxSpeed
    Maximum allowed speed imposed by this blocker, stored as a byte (0–255). In older save formats (before Version.trafficBottlenecks) the value was stored as a float; during deserialization the float is multiplied by 5 and clamped to [0,255] to convert into this byte range.

Properties

  • (none)

Constructors

  • public Blocker()
    No explicit constructors are defined in the type; it uses the default parameterless struct constructor. Initialize fields directly when creating instances.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component state to the provided writer in the following order:
  • m_Blocker (Entity)
  • m_Type (written as a byte)
  • m_MaxSpeed (byte)

This explicit ordering must be preserved to remain compatible with the corresponding Deserialize implementation.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads data back from the reader and handles two different storage formats:
  • If reader.context.version >= Version.trafficBottlenecks:
    • Reads a byte (used as the BlockerType value) into a local byte value.
    • Reads a byte into m_MaxSpeed.
    • Sets m_Type = (BlockerType)value.
  • Else (older formats):
    • Reads a float value2 (legacy max-speed representation).
    • Converts it to the current byte format: m_MaxSpeed = (byte)math.clamp(value2 * 5f, 0f, 255f).
    • Sets m_Type = BlockerType.None.

Notes: - The method reads the entity by ref into m_Blocker. - The logic preserves backward compatibility by translating legacy float speed to the new byte scale and defaulting the type to None when the type wasn't stored in older versions.

Usage Example

// Create and attach a Blocker to an entity (EntityManager example)
var blockerComp = new Blocker
{
    m_Blocker = blockingEntity,
    m_Type = BlockerType.Vehicle, // BlockerType is an enum defined elsewhere
    m_MaxSpeed = 120              // 0..255
};

entityManager.AddComponentData(targetEntity, blockerComp);

// The ISerializable implementation ensures this data is saved and loaded.
// When loading older saves (pre-trafficBottlenecks), m_MaxSpeed will be
// reconstructed from the legacy float value and m_Type will be set to None.

Additional notes for modders: - Because Blocker implements IComponentData, it is intended to be used with Unity's ECS (EntityManager, queries, and jobs). Treat it as a plain-old-data struct when accessing from jobs. - BlockerType is serialized as a single byte — avoid changing the enum layout without considering save compatibility. - The Deserialize method relies on Version.trafficBottlenecks being available in reader.context.version; when creating custom save handlers or tools, honor the same versioning scheme to maintain compatibility.