Skip to content

Game.Vehicles.CarNavigation

Assembly:
Assembly-CSharp

Namespace:
Game.Vehicles

Type:
public struct CarNavigation : IComponentData, IQueryTypeParameter, ISerializable

Base:
System.ValueType

Summary:
Component data used by the game's ECS to drive vehicle navigation for cars. It stores a target world position, a target rotation (orientation) and a maximum permitted speed. The struct implements the game's binary serialization interface and contains logic to remain compatible with older saved-data formats (it handles a legacy rotation stored as a float3 before the parkingRotation version).


Fields

  • public Unity.Mathematics.float3 m_TargetPosition
    Position in world space that the vehicle is navigating toward.

  • public Unity.Mathematics.quaternion m_TargetRotation
    Target orientation for the vehicle. For compatibility with older save formats, this may be constructed from a legacy float3 direction when reading older versions.

  • public System.Single m_MaxSpeed
    Maximum desired speed for the vehicle while navigating toward the target (units depend on game physics).

Properties

  • This type does not declare any properties.

Constructors

  • public CarNavigation()
    No explicit constructor is declared in the source — this is a plain value-type (struct). Instances are default-initialized unless populated by user code or by ECS when added as component data.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the three fields into the provided writer in the following order: m_TargetPosition, m_TargetRotation, m_MaxSpeed. Used by the game's save/serialization system.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the component data from the provided reader. Deserialization behavior:

  • Always reads m_TargetPosition first.
  • If reader.context.version >= Version.parkingRotation then it reads m_TargetRotation directly (newer format).
  • Else (older format) it reads a legacy float3 value. If that legacy value is not the zero vector, it converts it into a quaternion via quaternion.LookRotationSafe(value, math.up()) and stores it into m_TargetRotation (preserves rotation information stored in older versions as a direction).
  • Finally reads m_MaxSpeed. This preserves compatibility with saves written before the introduction of parkingRotation.

Usage Example

// Example: creating and assigning a CarNavigation component to an entity
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using Game.Vehicles;

// create and populate the component
var nav = new CarNavigation
{
    m_TargetPosition = new float3(100f, 0f, 250f),
    m_TargetRotation = quaternion.LookRotationSafe(new float3(0f, 0f, 1f), math.up()),
    m_MaxSpeed = 20f
};

// assume entityManager and an entity are available
entityManager.AddComponentData(entity, nav);

Notes for modders: - When modifying serialization behavior or version checks, ensure compatibility with the game's Version flags (e.g., Version.parkingRotation) so older saves continue to load correctly. - The component is a pure data container (IComponentData). Any runtime logic that uses these values (pathfinding, steering, speed control) will be implemented elsewhere in systems that read this component.