Game.NetObject
Assembly:
Likely compiled into the game's main assembly (game-specific assembly name may vary)
Namespace:
Game.Objects
Type:
struct
Base:
Implements: Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable
Summary:
Represents a compact component that stores net-object flags for ECS entities (used for network/road objects in Cities: Skylines 2). This struct is an ECS component that can be attached to entities and supports custom binary serialization via the Colossal.Serialization ISerializable interface. The flags are stored as a byte when serialized, so the backing enum (NetObjectFlags) should fit within a byte.
Fields
public NetObjectFlags m_Flags
Stores the flags for the net object (bitmask). These flags describe state/behavior for the net object and are written/read as a single byte during serialization. Ensure that NetObjectFlags values fit in a byte to avoid truncation.
Properties
- None (this is a plain struct component with a public field)
Constructors
- Implicit default constructor (value-initialized struct)
No explicit constructors are defined. You can create one with object initializer syntax:new NetObject { m_Flags = ... }
.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component data to the provided writer. Implementation casts the NetObjectFlags to a byte and calls writer.Write(byte). This produces a compact single-byte representation for the flags. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads a byte from the reader and converts it back into the NetObjectFlags enum. Uses reader.Read(out byte value) and casts the read byte to NetObjectFlags.
Notes on serialization: - The implementation serializes only the flags as a single byte. If NetObjectFlags grows beyond 8 bits in the future, serialization must be updated accordingly. - The serialization APIs used are the Colossal.Serialization IWriter/IReader abstractions used by the game's save/load and network systems.
Usage Example
// Create an entity with the NetObject component and set flags
var em = Unity.Entities.World.DefaultGameObjectInjectionWorld.EntityManager;
var archetype = em.CreateArchetype(typeof(Game.Objects.NetObject));
var entity = em.CreateEntity(archetype);
// Assume NetObjectFlags has values like Active, Render, etc.
em.SetComponentData(entity, new Game.Objects.NetObject { m_Flags = NetObjectFlags.Active | NetObjectFlags.Render });
// Example: manual serialization with a generic writer (pseudo-code, depends on writer implementation)
var netObj = em.GetComponentData<Game.Objects.NetObject>(entity);
// TWriter must implement IWriter from Colossal.Serialization.Entities
// writer.Write((byte)netObj.m_Flags); // that's what Serialize would do
// Example: manual deserialization (pseudo-code)
Game.Objects.NetObject loaded = default;
// TReader must implement IReader from Colossal.Serialization.Entities
// reader.Read(out byte value);
// loaded.m_Flags = (NetObjectFlags)value; // that's what Deserialize does
Additional tips: - Access and mutate this component via Unity.Entities systems (Entities.ForEach, SystemBase, or ISystem) to remain compatible with ECS threading and safety constraints. - When adding new flag values to NetObjectFlags, ensure backward compatibility with saved data and the single-byte serialization format.