Skip to content

Game.Prefabs.CarTractor

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
Component used on vehicle prefabs to configure tractor (towing) behavior. Exposes which trailer type to use, the attach offset for the trailer connection, and an optional fixed trailer prefab reference. It integrates with the prefab dependency and ECS component systems by adding the required trailer prefab dependency and the runtime CarTractorData component to the prefab's component list. The class is also decorated with a ComponentMenu attribute so it appears under Vehicles in the Unity inspector for Car and CarTrailer prefabs.


Fields

  • public CarTrailerType m_TrailerType
    Specifies the trailer connection type for this tractor (e.g., Towbar). Determines how trailers are attached/handled by the vehicle.

  • public float3 m_AttachOffset
    Attachment offset (local space) where the trailer should be connected. Default in code: float3(0f, 0.5f, 0f). Adjust this to position the trailer hitch relative to the tractor model.

  • public CarTrailerPrefab m_FixedTrailer
    Optional reference to a specific trailer prefab that this tractor will always use. If set, this prefab is added to the prefab dependency list so it will be loaded/available at runtime.

Properties

  • (No public properties defined by this class.)

Constructors

  • public CarTractor()
    Default parameterless constructor (implicit). Fields use their default initializers as declared in the class (m_TrailerType defaults to CarTrailerType.Towbar, m_AttachOffset defaults to float3(0,0.5,0), m_FixedTrailer defaults to null).

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Adds any prefab dependencies required by this component to the provided list. Implementation checks m_FixedTrailer and, if non-null, adds it to the prefabs list so the trailer prefab is included when building/loading the main prefab.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Registers runtime ECS components required by the prefab. This implementation adds the CarTractorData component (read/write) to the supplied components set so entities created from the prefab include tractor-related data.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Present but empty in this implementation. Intended to add components directly to an archetype during prefab creation if needed; this class does not add any archetype-only components here.

Usage Example

// Example: configure a CarTractor on a prefab in code (or show expected inspector usage)
var tractor = new CarTractor
{
    m_TrailerType = CarTrailerType.Towbar,
    m_AttachOffset = new float3(0f, 0.5f, 0f),
    m_FixedTrailer = someTrailerPrefab // optional reference to a CarTrailerPrefab
};

// When prefabs are processed, GetDependencies will add `someTrailerPrefab` (if set)
// and GetPrefabComponents will ensure the runtime CarTractorData component is present.

Additional notes: - The ComponentMenu attribute places this component under Vehicles in the Unity Add Component menu for CarPrefab and CarTrailerPrefab types. - CarTractor works together with runtime CarTractorData and trailer-handling systems; changing the attach offset or trailer prefab affects in-game attachment/physics/visuals of trailers.