Skip to content

Game.Prefabs.CarPrefab

Assembly: Game
Namespace: Game.Prefabs

Type: Class

Base: CarBasePrefab

Summary:
CarPrefab is a prefab descriptor used by the game's entity/prefab system to enumerate which ECS components should be present on car prefabs and on the archetypes created from them. It overrides component-collection hooks to add runtime data components (e.g., CarData, SwayingData) to the prefab and to add runtime ECS components (e.g., Car, BlockedLane) to the archetype. The class delegates to its base implementation first and then appends vehicle-specific components. Some archetype components are added conditionally depending on whether certain marker components (Stopped or Moving) are present in the provided components set.


Fields

  • This class does not declare any instance or static fields in the source shown.
    {{ The class only implements behavior through overridden methods; data is represented via components added to prefabs/archetypes rather than fields on the prefab class itself. }}

Properties

  • This class does not declare any properties.
    {{ Component membership and runtime state are represented through ECS components rather than C# properties on the prefab. }}

Constructors

  • public CarPrefab()
    {{ Uses the default parameterless constructor (no explicit constructor is declared in the source). Instances are typically created/managed by the game's prefab system rather than manually constructed by mods. }}

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    {{ Adds prefab-level component types required by car prefabs. Implementation notes:
  • Calls base.GetPrefabComponents(components) first.
  • Adds ComponentType.ReadWrite() and ComponentType.ReadWrite().
  • CarData holds per-prefab/per-instance car configuration/state that the vehicle systems use.
  • SwayingData enables visual/physical swaying behavior for the vehicle meshes.
  • This method is used by the prefab system to determine which data blobs should be serialized with or instantiated for the prefab. }}

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    {{ Adds archetype-level ECS component types required for cars. Implementation notes:

  • Calls base.GetArchetypeComponents(components) first.
  • Always adds ComponentType.ReadWrite() and ComponentType.ReadWrite().
  • If the components set already contains ComponentType.ReadWrite(), it also adds ComponentType.ReadWrite().
  • If the components set already contains ComponentType.ReadWrite(), it adds a set of movement/navigation related components:
    • ComponentType.ReadWrite()
    • ComponentType.ReadWrite()
    • ComponentType.ReadWrite()
    • ComponentType.ReadWrite()
    • ComponentType.ReadWrite()
    • ComponentType.ReadWrite()
    • ComponentType.ReadWrite()
    • ComponentType.ReadWrite()
  • These conditionally added components allow the entity archetype to support driving behavior (path ownership, current lane tracking, target/path elements) or parking behavior (ParkedCar) depending on whether the prefab/archetype is intended for moving or stopped cars.
  • The method is used by the ECS archetype creation to compose the full set of components that car entities will have at runtime. }}

Usage Example

// The game engine calls these methods when preparing prefabs/archetypes.
// A modder could derive from CarPrefab to add or change components:
public class MyCustomCarPrefab : CarPrefab
{
    public override void GetPrefabComponents(HashSet<ComponentType> components)
    {
        base.GetPrefabComponents(components);
        // Add a custom per-prefab component
        components.Add(ComponentType.ReadWrite<MyCustomCarData>());
    }

    public override void GetArchetypeComponents(HashSet<ComponentType> components)
    {
        base.GetArchetypeComponents(components);
        // Ensure all moving cars also get a custom runtime component
        if (components.Contains(ComponentType.ReadWrite<Moving>()))
        {
            components.Add(ComponentType.ReadWrite<MyRuntimeCarComponent>());
        }
    }
}

{{ Tips: - Use these overrides to ensure your custom car prefabs include any data your systems expect at both prefab and runtime (archetype) levels. - Order: always call base.* first to preserve base-class component requirements. - Be mindful of conditional additions: checking for marker components like Moving or Stopped is a way to add movement- or parking-specific components only when appropriate. - Added ComponentType entries typically correspond to small structs (IComponentData) used by ECS systems; ensure those component types are implemented and available to the runtime. }}