Game.WatercraftCurrentLane
Assembly:
Assembly-CSharp (game code) {{ YOUR_INFO: This struct is part of the game's runtime assemblies; when modding, it's usually found in Assembly-CSharp. }}
Namespace:
Game.Vehicles
Type:
struct WatercraftCurrentLane
Base:
IComponentData, IQueryTypeParameter, ISerializable
Summary:
{{ YOUR_INFO: WatercraftCurrentLane represents the current lane-related state for a water vehicle while pathfollowing. It stores references to the lane entity the craft is on (and a lane it is changing to, if any), the local curve position on that lane, lane flags, and numeric progress metrics used by the pathing/movement systems (lane change progress, duration, distance travelled along the lane and a lane-position value that is gated by serialization version). This struct is a Unity ECS component (IComponentData) and supports custom (de)serialization via ISerializable. }}
Fields
-
public Entity m_Lane
{{ YOUR_INFO: The current lane entity the watercraft is using (Unity.Entities.Entity). Set from a PathElement's target when the component is constructed. Serialized first. }} -
public Entity m_ChangeLane
{{ YOUR_INFO: The target lane entity for a lane change (Entity.Null if not changing lanes). Serialized second. }} -
public float3 m_CurvePosition
{{ YOUR_INFO: Local curve/tangent offset on the lane, represented as a float3. Constructed from PathElement.m_TargetDelta.xxx. Serialized third. }} -
public WatercraftLaneFlags m_LaneFlags
{{ YOUR_INFO: Flags describing lane properties or state (enum type WatercraftLaneFlags). Stored as a uint when serialized (see Deserialize cast). Serialized after curve position (written as uint). }} -
public float m_ChangeProgress
{{ YOUR_INFO: Progress value [0..1] for an ongoing lane change. Serialized as a float. }} -
public float m_Duration
{{ YOUR_INFO: Duration metric (usage depends on the movement system — e.g., lane change or traversal timing). }} -
public float m_Distance
{{ YOUR_INFO: Distance traveled along the current lane segment. }} -
public float m_LanePosition
{{ YOUR_INFO: Additional lane-position float introduced in a later save version. The field is only read during deserialization when reader.context.version >= Version.lanePosition. When not present in save data, it remains whatever default value exists (constructor sets to 0f). }}
Properties
{{ YOUR_INFO: This type does not declare any C# properties. It exposes raw public fields only. }}
Constructors
public WatercraftCurrentLane(PathElement pathElement, WatercraftLaneFlags flags)
{{ YOUR_INFO: Creates and initializes a WatercraftCurrentLane from a PathElement and initial flags. Sets m_Lane to pathElement.m_Target, m_ChangeLane to Entity.Null, m_CurvePosition from pathElement.m_TargetDelta.xxx, m_LaneFlags from the provided flags, and numeric fields (m_ChangeProgress, m_Duration, m_Distance, m_LanePosition) to 0f. Use this when creating the component at the time a vehicle enters a lane. }}
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
{{ YOUR_INFO: Writes the component state to the provided writer in a fixed order: m_Lane, m_ChangeLane, m_CurvePosition, m_LaneFlags (written as uint), m_ChangeProgress, m_Duration, m_Distance, m_LanePosition. Used by the game's save system to persist vehicle lane state. The method relies on the concrete writer implementation to correctly handle Entity and float3 types. }} -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
{{ YOUR_INFO: Reads component state from the reader in the same order used by Serialize. It reads into the existing struct fields by reference. The method reads a uint for the stored lane flags and casts it back to WatercraftLaneFlags at the end. The code handles save compatibility by only reading m_LanePosition if reader.context.version >= Version.lanePosition; older saves will not contain that value. Ensure the reader.context.version is checked for additional future fields similarly. }}
Usage Example
// Create a WatercraftCurrentLane when initializing a vehicle from a path element:
PathElement pathElement = /* obtained from pathfinding */;
WatercraftLaneFlags initialFlags = WatercraftLaneFlags.None;
var currentLane = new WatercraftCurrentLane(pathElement, initialFlags);
// Add as a component on an entity (example using Entities API):
// entityManager.AddComponentData(vehicleEntity, currentLane);
{{ YOUR_INFO: Notes for modders: - Because this is an IComponentData, you can add it to ECS entities representing vehicles to track lane state. - The struct implements ISerializable for game save/load compatibility — if you modify the struct layout, ensure you update serialization versioning to avoid breaking saves. - m_Lane and m_ChangeLane are Entity handles; when working with these you may need to resolve lane entity components to query lane geometry or flags. - Be mindful of the version check for m_LanePosition when interacting with saved data. }}