Skip to content

Game.Net.Edge

Assembly: Game
Namespace: Game.Net

Type: struct

Base: System.ValueType
Implements: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Edge is an ECS component representing a connection between two Entities (typically network/node Entities) in the game's Net system. It stores the start and end Entity references and provides custom binary serialization/deserialization via the Colossal.Serialization entities reader/writer interfaces. Use this component to represent edges in graph-like data (roads, connections, network segments) and to persist those references across save/load operations.


Fields

  • public Entity m_Start
    Represents the starting endpoint Entity of the edge. This is an Entity reference from Unity.Entities. It may be Entity.Null if not set. When serialized, the Entity is written using the provided IWriter implementation (which typically handles remapping between runtime/save IDs).

  • public Entity m_End
    Represents the ending endpoint Entity of the edge. Behaves the same as m_Start with respect to validity and serialization.

Properties

  • This type defines no properties. The fields m_Start and m_End are exposed publicly.

Constructors

  • public Edge()
    Structs have an implicit parameterless constructor which initializes Entities to their default (usually Entity.Null). You can initialize instances with object initializer syntax: Edge e = new Edge { m_Start = startEntity, m_End = endEntity };

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the two Entity fields to the provided writer in order (m_Start then m_End). The writer is expected to know how to serialize Entity references (Colossal.Serialization.Entities helpers). This method is used when saving or network-synchronizing component data.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the two Entity fields from the provided reader in the same order they were written. Deserialization uses out/ref semantics to populate the struct's fields. The reader must be the corresponding counterpart to the writer used during serialization so that Entity remapping works correctly.

Notes: - The type constraints ensure that only compatible reader/writer implementations are used. - Serialization writes Entities directly; game save/load logic must handle Entity ID remapping between sessions.

Usage Example

// Example usage in a system or utility:
// - creating an Edge component
// - setting it on an entity (EntityManager example)
// - serializing/deserializing generically

// Create an Edge instance
Edge edge = new Edge
{
    m_Start = startEntity, // existing Entity that represents a node
    m_End = endEntity      // existing Entity that represents another node
};

// Add or set component data on an entity using an EntityManager (example)
entityManager.AddComponentData(someEdgeEntity, edge);

// Generic save helper
void SaveEdge<TWriter>(ref Edge e, TWriter writer) where TWriter : IWriter
{
    e.Serialize(writer);
}

// Generic load helper
Edge LoadEdge<TReader>(TReader reader) where TReader : IReader
{
    Edge e = default;
    e.Deserialize(reader);
    return e;
}

// When serializing/deserializing ensure you use the game's expected
// IWriter/IReader implementations so Entity reference remapping is correct.

{{ This component is a simple POD ECS struct intended for use inside the Cities: Skylines 2 modding environment. Keep in mind: - Entity references may be invalid across domain reloads or without proper remapping during save/load. - The serialization functions rely on the Colossal.Serialization.Entities ecosystem; do not attempt to replace them with custom binary formats unless you also implement compatible Entity remapping. - Because Edge is an IComponentData, it can be used in Jobs/Systems following Unity DOTS patterns, but be careful to respect safety and thread-safety rules when accessing EntityManager or other non-thread-safe APIs. }}