Skip to content

Game.Vehicles.ParkedCar

Assembly: Assembly-CSharp (typical runtime assembly for game code)
Namespace: Game.Vehicles

Type: struct

Base: Implements IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents a parked car component used by the ECS world. The component stores a reference to the lane Entity where the car is parked and a float describing the curve position along that lane. This struct is serializable via the Colossal.Serialization.Entities IWriter/IReader abstractions and can be attached to ECS entities as IComponentData. The component is intended for use by vehicle/traffic systems to locate parked cars along lane splines.


Fields

  • public Entity m_Lane
    Stores the Entity that identifies the lane the car is parked on. This is written first during serialization and read first during deserialization.

  • public float m_CurvePosition
    Stores the position along the lane curve where the car is parked. Typically used as a curve offset/position (commonly normalized 0..1 depending on the lane/spline implementation). This is written second during serialization and read second during deserialization.

Properties

  • None.
    This struct exposes only public fields and implements interfaces; there are no C# properties.

Constructors

  • public ParkedCar(Entity lane, float curvePosition)
    Initializes a new ParkedCar instance with the given lane Entity and curve position.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes component state to a writer in the following order: m_Lane, then m_CurvePosition. This is used by the game's serialization pipeline to persist component data.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads component state from a reader in the same order it was written (m_Lane then m_CurvePosition). The method uses ref locals to populate the struct fields directly.

Usage Example

// Creating a ParkedCar component
Entity someLaneEntity = /* obtain lane entity from lane lookup */;
float positionOnLane = 0.42f;
ParkedCar parked = new ParkedCar(someLaneEntity, positionOnLane);

// Serializing the component (writer obtained from serialization system)
public void SaveParked(ParkedCar p, IWriter writer)
{
    p.Serialize(writer);
}

// Deserializing into an existing ParkedCar instance (reader obtained from serialization system)
public void LoadParked(ref ParkedCar p, IReader reader)
{
    p.Deserialize(reader);
}

// Attaching to an ECS entity
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity carEntity = entityManager.CreateEntity();
entityManager.AddComponentData(carEntity, parked);

Notes and tips: - Order of Serialize/Deserialize must match exactly (m_Lane then m_CurvePosition). - Because this struct implements IComponentData, it is intended to be attached directly to entities in the Unity Entities (ECS) world. - As an IQueryTypeParameter, the type can be used in queries/for-each systems that accept this parameter type. - The concrete meaning and valid range of m_CurvePosition depend on lane spline conventions in the vehicle system; commonly it is normalized (0..1) but confirm with the lane API before relying on that range.