Skip to content

Game.Net.ConnectedNode

Assembly: Game
Namespace: Game.Net

Type: struct

Base: System.ValueType, Unity.Entities.IBufferElementData, System.IEquatable, Colossal.Serialization.Entities.ISerializable

Summary:
ConnectedNode is a small buffer element type used to represent a connection from one node entity to another in the game's net/road graph. It stores the target node Entity and a float "curve position" that typically encodes the position along a curve or ordering information. The struct implements IBufferElementData so it can be stored in a DynamicBuffer on an Entity, and implements custom serialization methods for the game's Colossal serializer. Note the [InternalBufferCapacity(0)] attribute which indicates no inline capacity is reserved for this buffer element.


Fields

  • public Unity.Entities.Entity m_Node
    Represents the target node Entity this connection points to. Equality (Equals method) is based only on this field.

  • public System.Single m_CurvePosition
    A float value representing the position along a curve or an ordering value for the connection. Used by game logic to place or sort connections along a curve.

Properties

  • This struct does not declare any properties. All data is exposed via public fields.

Constructors

  • public ConnectedNode(Unity.Entities.Entity node, System.Single curvePosition)
    Initializes a ConnectedNode with the given node Entity and curve position.

Methods

  • public bool Equals(ConnectedNode other)
    Compares this ConnectedNode to another. Implementation compares only the m_Node field (it uses m_Node.Equals(other.m_Node)), so two ConnectedNode instances pointing to the same node are considered equal regardless of m_CurvePosition.

  • public override int GetHashCode()
    Computes a hash code using both m_Node and m_CurvePosition. The implementation multiplies and combines hash codes of the fields.

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the m_Node and m_CurvePosition fields to the provided writer. Used by the game's Colossal serializer for persisting this buffer element.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads m_Node and m_CurvePosition from the provided reader into the struct's fields. Uses ref locals to read directly into fields.

Usage Example

// Example: add a ConnectedNode to an entity's DynamicBuffer<ConnectedNode>
using Unity.Entities;
using Game.Net;

// Assume you have valid EntityManager, ownerEntity and nodeEntity:
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity ownerEntity = /* the entity that holds the buffer */;
Entity nodeEntity = /* the connected node entity */;
float curvePos = 0.25f;

// Ensure the buffer type exists on ownerEntity (usually via an archetype or AddBuffer)
var buffer = em.GetBuffer<ConnectedNode>(ownerEntity);
buffer.Add(new ConnectedNode(nodeEntity, curvePos));

// Note on serialization:
// The struct implements Serialize/Deserialize used by Colossal's serializer.
// When saving/loading or sending across the network, those methods are used
// to persist the m_Node and m_CurvePosition values.

Additional notes: - Because Equals only compares m_Node, be careful when using ConnectedNode instances as keys in collections where curve position matters — equality ignores m_CurvePosition. - The InternalBufferCapacity(0) attribute means buffers of this element type start with no inline capacity; adding elements may allocate storage.