Skip to content

Game.Prefabs.NetZoneData

Assembly:
Namespace: Game.Prefabs

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
NetZoneData is a lightweight ECS component (IComponentData) used to store a reference to a block prefab (Entity) representing a network zone block. It implements ISerializable to participate in Colossal's serialization system (used by Cities: Skylines 2 for saving/loading and prefab persistence) and IQueryTypeParameter to be usable as a query parameter in ECS queries. This struct is intended for modders to attach prefab references to entities that represent net zone blocks so systems can read, serialize, and recreate those references.


Fields

  • public Unity.Entities.Entity m_BlockPrefab
    Holds an Entity reference to the block prefab associated with this net zone. This Entity is typically a prefab Entity (not a runtime instance) used by systems that spawn or inspect net zone blocks. The field is public and can be read/written directly when creating or modifying component data.

Properties

  • None

Constructors

  • public NetZoneData(Unity.Entities.Entity blockPrefab)
    Creates a new NetZoneData with the supplied prefab Entity. Use this constructor to initialize the component when adding it to an entity via EntityManager or when creating component data to assign to an entity.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the m_BlockPrefab Entity to the provided writer. This allows the component to be saved into game data or prefab streams handled by Colossal.Serialization.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads an Entity out of the provided reader into m_BlockPrefab. This is used when loading saved data or instantiating prefabs so the prefab reference is restored.

Usage Example

// Create the component with a reference to a prefab entity
var blockPrefabEntity = /* obtain prefab Entity from prefab manager or similar */;
var netZoneData = new NetZoneData(blockPrefabEntity);

// Add to an entity (EntityManager example)
entityManager.AddComponentData(someEntity, netZoneData);

// Serialization is handled by the game's serialization pipeline, but the methods
// can be called directly if implementing custom read/write flows:
using (var writer = /* your IWriter implementation */) {
    netZoneData.Serialize(writer);
}

using (var reader = /* your IReader implementation */) {
    var loaded = new NetZoneData();
    loaded.Deserialize(reader);
    // now loaded.m_BlockPrefab contains the restored Entity reference
}

{{ Additional notes for modders: - The Unity.Entities.Entity stored here is typically a prefab reference; ensure you manage prefab lifetimes via the game's prefab manager systems to avoid dangling references. - Because this is an IComponentData struct, it is blittable and intended to be used on the ECS main thread or via safe ECS APIs. - Implementing ISerializable ensures compatibility with Colossal's save/load and prefab serialization; do not remove or change the signature of Serialize/Deserialize unless you also update the corresponding serialization handling. - IQueryTypeParameter is used to make this type usable as a parameter in queries; consult the game's ECS query utilities for examples of using types as query parameters. }}