Skip to content

Game.VehicleCarriageElement

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: struct

Base: Unity.Entities.IBufferElementData

Summary:
Represents a single carriage entry for a vehicle prefab in the ECS buffer. Each element points to a carriage prefab (Entity), contains a two-component int2 describing a min/max count (used to spawn between min and max carriage units), and a VehicleCarriageDirection value describing how the carriage is oriented/attached. The struct is intended to be used inside a DynamicBuffer on a vehicle prefab entity or a configuration entity. The [InternalBufferCapacity(0)] attribute specifies no inline/static storage (buffer is dynamically allocated).


Fields

  • public Unity.Entities.Entity m_Prefab
    Reference to the carriage prefab Entity that should be instantiated/attached for this carriage element.

  • public Unity.Mathematics.int2 m_Count
    Holds the minimum and maximum counts: x = minCount, y = maxCount. Use these values when spawning multiple carriage instances for variability (e.g., choose a random value in the inclusive range [x, y]).

  • public VehicleCarriageDirection m_Direction
    Specifies the direction/orientation the carriage should have relative to the parent vehicle. VehicleCarriageDirection is expected to be an enum defined elsewhere in the project/mod providing attachment/orientation semantics.

Properties

  • This type does not declare any properties. It is a plain IBufferElementData struct with public fields.

Constructors

  • public VehicleCarriageElement(Entity carriage, int minCount, int maxCount, VehicleCarriageDirection direction)
    Creates a new VehicleCarriageElement instance.
  • carriage: Entity referencing the carriage prefab.
  • minCount: minimum number of carriage units to spawn for this element.
  • maxCount: maximum number of carriage units to spawn for this element.
  • direction: orientation/attachment direction for the carriage.

Methods

  • This type does not declare any methods. It is a simple data container used in DynamicBuffer.

Usage Example

// Example: adding carriage elements to an entity's buffer inside a system or authoring conversion.

var carriagePrefabEntity = /* obtain prefab Entity */;
var direction = VehicleCarriageDirection.Back; // example enum value
int min = 1;
int max = 3;

// Assuming 'entityManager' and 'entity' are available and the buffer has been added to the entity:
var buffer = entityManager.GetBuffer<VehicleCarriageElement>(entity);
buffer.Add(new VehicleCarriageElement(carriagePrefabEntity, min, max, direction));

// When spawning, a system can read each VehicleCarriageElement and instantiate
// anywhere between m_Count.x and m_Count.y copies of m_Prefab and apply m_Direction.

Additional notes: - Because InternalBufferCapacity is set to 0, the buffer starts empty and uses dynamic memory growth when elements are added. - Ensure the referenced prefab Entity is valid and registered as a prefab when instantiating at runtime. - The semantics of VehicleCarriageDirection (values and meaning) are defined in its enum; consult that definition for correct orientation handling.