Skip to content

Game.CarKeeper

Assembly:
Assembly-CSharp (game code / modding assembly)

Namespace:
Game.Citizens

Type:
struct (IComponentData)

Base:
Implements: IComponentData, IQueryTypeParameter, IEmptySerializable, IEnableableComponent

Summary:
CarKeeper is a lightweight DOTS ECS component that stores a reference to an Entity representing a car associated with the owning entity (for example, a citizen's personal vehicle). It is an enableable, empty-serializable value-type component used by systems to track or link a car Entity to another Entity. Use Entity.Null to represent "no car".


Fields

  • public Unity.Entities.Entity m_Car
    Holds the Entity handle for the car associated with the owner. When there is no assigned car, this should be Entity.Null. Systems can read or update this field to associate/dissociate cars.

Properties

  • None (no managed or auto properties are defined on this struct).
    Note: The component is a plain IComponentData struct; access is via the field or through EntityManager/EntityCommandBuffer operations.

Constructors

  • public CarKeeper()
    Structs have a default parameterless constructor. The default value for m_Car will be Entity.Null (the default for an Entity).

Methods

  • None (no methods are declared on the struct itself).
    Behavior is provided by systems that read/write the component and by Unity.Entities APIs for enable/disable and serialization.

Usage Example

// Add component to an entity and assign a car
var carKeeper = new CarKeeper { m_Car = carEntity }; // carEntity is a Unity.Entities.Entity
entityManager.AddComponentData(ownerEntity, carKeeper);

// Read and check
var ck = entityManager.GetComponentData<CarKeeper>(ownerEntity);
if (ck.m_Car != Entity.Null)
{
    // do something with ck.m_Car
}

// Update association
ck.m_Car = Entity.Null; // remove association
entityManager.SetComponentData(ownerEntity, ck);

// Enable/disable the component (IEnableableComponent)
entityManager.SetComponentEnabled<CarKeeper>(ownerEntity, true);  // enable
entityManager.SetComponentEnabled<CarKeeper>(ownerEntity, false); // disable

Additional notes: - Because CarKeeper implements IEmptySerializable, it participates in the game's custom serialization pipeline (used by the game/mods to save/load component state). - As an enableable component, CarKeeper can be toggled on/off per-entity without removing the component, which is useful for conditional processing by systems.