Skip to content

Game.Creatures.CurrentVehicle

Assembly:
Assembly-CSharp

Namespace: Game.Creatures

Type: struct

Base: System.ValueType

Summary: CurrentVehicle is an ECS component (struct) used to store a reference to the vehicle entity currently associated with a creature and a set of flags describing that relationship. It implements IComponentData so it can be attached to entities, IQueryTypeParameter for use in queries, and ISerializable to support save/load serialization. The vehicle Entity is serialized and the flags are written as a uint.


Fields

  • public Unity.Entities.Entity m_Vehicle Holds the Entity id of the vehicle currently used by the creature. This is the primary reference to the vehicle entity in the ECS world.

  • public CreatureVehicleFlags m_Flags Bitmask/enum describing the creature-to-vehicle relationship (e.g., driver/passenger state, temporary ownership, etc.). Stored and serialized as a uint.

Properties

  • This type has no properties.

Constructors

  • public CurrentVehicle(Unity.Entities.Entity vehicle, CreatureVehicleFlags flags) Initializes a new CurrentVehicle instance with the given vehicle Entity and flags.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter Writes the component data into the provided writer for persistence. Implementation writes the Entity (m_Vehicle) and then writes m_Flags cast to uint.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader Reads the component data from the provided reader. Implementation reads the Entity into m_Vehicle, reads a uint value and casts it back to CreatureVehicleFlags for m_Flags.

Usage Example

// Assuming you have an EntityManager and valid entity references:
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

// Create a CurrentVehicle component and attach it to a creature entity
var vehicleEntity = /* obtain vehicle entity */;
var creatureEntity = /* obtain creature entity */;
var flags = CreatureVehicleFlags.None; // example flag value

var currentVehicle = new Game.Creatures.CurrentVehicle(vehicleEntity, flags);
entityManager.AddComponentData(creatureEntity, currentVehicle);

// Example: custom serialization usage (pseudocode, depends on mod API)
void SaveComponent<TWriter>(TWriter writer, Game.Creatures.CurrentVehicle comp) where TWriter : IWriter
{
    comp.Serialize(writer);
}

void LoadComponent<TReader>(TReader reader, out Game.Creatures.CurrentVehicle comp) where TReader : IReader
{
    comp = new Game.Creatures.CurrentVehicle();
    comp.Deserialize(reader);
}