Skip to content

Game.Prefabs.CarTrailerPrefab

Assembly: Assembly-CSharp (typical for game mods)
Namespace: Game.Prefabs

Type: class

Base: CarBasePrefab

Summary:
Prefab class representing a car trailer configuration used by the game's vehicle prefab system. Provides serialized fields to configure trailer type, movement behavior, attach offset and an optional fixed tractor prefab. Contributes required ECS components and archetype components for trailers (e.g., CarTrailer, CarTrailerLane, Swaying) when prefabs and archetypes are being constructed. Intended to be used by the prefab pipeline / inspector to create trailer variants for vehicles.


Fields

  • public CarTrailerType m_TrailerType = CarTrailerType.Towbar
    Specifies the trailer coupling/type (default: Towbar). Determines trailer-specific behavior and visuals.

  • public TrailerMovementType m_MovementType
    Specifies how the trailer moves relative to the tractor (movement/physics behavior).

  • public float3 m_AttachOffset = new float3(0f, 0.5f, 0f)
    Local offset used to attach the trailer to the tractor. Default places the attach point 0.5 units above the trailer origin.

  • public CarBasePrefab m_FixedTractor
    Optional reference to a specific tractor prefab that this trailer is fixed to. If set, this prefab is added as a dependency so it is available when the trailer is used.

Properties

  • (No public properties declared in this class)
    All configuration is exposed via public fields; behavior is injected by overriding prefab methods.

Constructors

  • public CarTrailerPrefab()
    Implicit default constructor (no custom initialization beyond field defaults). Instances are typically created/managed by the prefab system or by Unity serialization.

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Calls base.GetDependencies(prefabs) and, if m_FixedTractor is not null, adds the referenced tractor prefab to the provided dependencies list. This ensures the tractor prefab is loaded/available when this trailer prefab is used.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Calls base.GetPrefabComponents(components) then adds these component types (read/write) required by trailer prefabs:

  • CarData
  • CarTrailerData
  • SwayingData
    These indicate that entities created from this prefab will hold the associated data components.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Calls base.GetArchetypeComponents(components) and ensures the archetype contains these components:

  • CarTrailer
  • Controller
  • BlockedLane
    Additionally:
  • If the archetype is expected to include Stopped, the method adds ParkedCar.
  • If the archetype is expected to include Moving, the method adds CarTrailerLane and Swaying.
    This conditional addition tailors the entity archetype depending on whether the vehicle is expected to be moving or parked/stopped.

Usage Example

// Typical usage is via Unity inspector or prefab setup code.
// Creating/configuring a trailer prefab in code (example):
var trailerPrefab = new CarTrailerPrefab
{
    m_TrailerType = CarTrailerType.Towbar,
    m_MovementType = TrailerMovementType.Jointed,
    m_AttachOffset = new float3(0f, 0.6f, 0f),
    m_FixedTractor = someTractorPrefab // optional reference to a tractor prefab
};

// Register the prefab with the game's prefab manager (pseudo-code):
PrefabManager.Register(trailerPrefab);

{{ Additional notes: - This class is part of the game's prefab system and integrates with the ECS (Unity.Entities) component model used by the game. - The component types referenced (CarData, CarTrailerData, SwayingData, etc.) are data components expected by runtime systems that handle movement, rendering and lane/parking logic. - When authoring mods that add or modify trailers, ensure the referenced component types and enums (CarTrailerType, TrailerMovementType) are compatible with the game's expected behaviors and data layouts. }}