Skip to content

Game.Vehicles.Car

Assembly:
Assembly-CSharp (typical for Cities: Skylines 2 mods)
Namespace:
Game.Vehicles

Type:
struct

Base:
IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents a lightweight ECS component for a car entity that stores car-specific flags. The struct implements serialization (ISerializable) so it can be written to/read from Colossal's serialization system and is usable as a Unity.Entities component (IComponentData) and as a query parameter (IQueryTypeParameter).


Fields

  • public CarFlags m_Flags
    Stores the car's flags (bitmask). The exact semantics depend on the CarFlags enum used by the game (e.g., status bits for behavior, state, or properties). This field is serialized as a 32-bit unsigned integer.

Properties

  • None.
    This struct exposes its data via the public field m_Flags and provides no additional properties.

Constructors

  • public Car(CarFlags flags)
    Creates a new Car component with the provided flags. This is the primary constructor used to initialize the component before adding it to an entity or serializing it.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the internal flags to the provided writer. The flags are cast to uint and written as a 32-bit unsigned integer. Use this when persisting the component state.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads a 32-bit unsigned integer from the provided reader, converts it to CarFlags, and stores it in m_Flags. Use this when restoring component state from serialized data.

Usage Example

// Creating a Car component and adding it to an entity:
var carComponent = new Car(CarFlags.SomeFlag | CarFlags.AnotherFlag);
entityManager.AddComponentData(carEntity, carComponent);

// Serializing the component (pseudo-code; actual writer depends on the serialization system in use):
// TWriter must implement IWriter from Colossal.Serialization.Entities
void WriteCar<TWriter>(TWriter writer, Car car) where TWriter : IWriter
{
    car.Serialize(writer);
}

// Deserializing the component:
Car ReadCar<TReader>(TReader reader) where TReader : IReader
{
    var car = new Car();
    car.Deserialize(reader);
    return car;
}

Notes: - CarFlags is an enum (bitmask). Ensure you use the correct enum values from the game's definitions. - Because this struct implements IComponentData, it is intended to be used with Unity's ECS (EntityManager, archetypes, queries). - Serialization methods are generic and rely on Colossal's IWriter/IReader interfaces — supply the correct implementation when saving/loading data.