Game.Routes.CurrentRoute
Assembly:
Likely Assembly-CSharp (game/mod assembly that contains game types) — this component is defined in the game's code under Game.Routes. If you compile this into a separate mod assembly, replace with your mod's assembly name.
{{ This struct is part of the game's runtime components and is typically found in the main game assembly (Assembly-CSharp). For mod authors: include this type's source or reference the assembly that contains it. }}
Namespace:
Game.Routes
{{ Types in this namespace relate to route and path management for vehicles/agents in the city. }}
Type:
struct (value type)
{{ CurrentRoute is a lightweight component meant to be attached to entities. }}
Base:
Implements:
- Unity.Entities.IComponentData
- Unity.Entities.IQueryTypeParameter
- Colossal.Serialization.Entities.ISerializable
{{ Being an IComponentData means it can be used as a DOTS ECS component. ISerializable allows it to be written/read by the game's serialization system (Colossal.Serialization). IQueryTypeParameter enables usage in some ECS query APIs. }}
Summary:
Holds a reference to a route Entity. It serializes/deserializes that Entity using the Colossal.Serialization writers/readers.
{{ Use this component to store which route entity is currently associated with a vehicle/agent or other route-using entity. The stored Entity represents another ECS entity that encodes route data (waypoints, segments, etc.). }}
Fields
public Unity.Entities.Entity m_Route
{{ The Entity reference to the route. This is the value that gets written/read in Serialize/Deserialize. It may be Entity.Null if there is no route. When accessing, ensure the EntityManager still considers the referenced entity valid. }}
Properties
- None
{{ There are no computed or encapsulated properties on this struct; the route is stored directly in the public field m_Route. }}
Constructors
public CurrentRoute(Unity.Entities.Entity route)
{{ Initializes the component with the provided route Entity. Example use: new CurrentRoute(routeEntity). There is also the implicit default constructor which will set m_Route to Entity.Null. }}
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : Colossal.Serialization.Entities.IWriter
{{ Writes the m_Route Entity to the provided writer. This is used by the game's save/load and network serialization systems. The writer's behavior for Entities typically translates internal entity references into a saveable form. }} -
public void Deserialize<TReader>(TReader reader) where TReader : Colossal.Serialization.Entities.IReader
{{ Reads an Entity value into m_Route from the provided reader. After deserialization, m_Route will refer to the deserialized route entity (or Entity.Null). Ensure any systems that use this component can handle remapped entity references if the reader performs entity remapping. }}
Usage Example
using Unity.Entities;
using Game.Routes;
// assume you have an EntityManager and two entities:
// - vehicleEntity: the entity that should reference a route
// - routeEntity: the entity that represents the route
var currentRoute = new CurrentRoute(routeEntity);
// add as a component to an entity
entityManager.AddComponentData(vehicleEntity, currentRoute);
// or update an existing component
entityManager.SetComponentData(vehicleEntity, currentRoute);
{{ Notes: - When serializing game state, the ISerializable implementation ensures the route Entity is saved/restored. - Be careful using Entity values across domain reloads or outside the world/EntityManager that created them; prefer storing or resolving route entities within the same World/EntityManager context. - If routeEntity can be Entity.Null, ensure systems consuming CurrentRoute handle that case gracefully. }}