Skip to content

Game.Net.Orphan

Assembly:
Assembly-CSharp (typical runtime assembly for Cities: Skylines 2 mods)
{{ This type is defined in the game's runtime assembly (commonly Assembly-CSharp). If you're compiling into a separate mod assembly, reference/compare with the game's assembly to ensure compatibility. }}

Namespace: Game.Net

Type: struct

Base: IComponentData, IQueryTypeParameter, IEmptySerializable
{{ Implements Unity.Entities.IComponentData so it can be attached to ECS entities. IQueryTypeParameter allows it to be used directly in query parameter lists. IEmptySerializable is a marker type from Colossal.Serialization.Entities used by the game's serialization infrastructure. }}

Summary: A lightweight ECS component that holds a reference to a "composition" entity. Typically used to mark an entity as an "orphan" with an associated composition Entity reference for game logic or serialization handling. The struct contains a single Entity field (m_Composition) and no behavior methods. {{ Use this component whenever you need to associate an entity with a separate composition entity that is considered orphaned or detached. Because it is an IComponentData it can be added/removed via EntityManager or an EntityCommandBuffer and used in jobs and queries. }}


Fields

  • public Unity.Entities.Entity m_Composition {{ The Entity reference that this Orphan component carries. Usually points to a "composition" entity related to this orphaned object. When reading this field ensure that the referenced Entity is still valid (it may have been destroyed or changed). }}

Properties

  • None.
    {{ This struct exposes no managed properties. It is a plain data container (value type) with a single public field. }}

Constructors

  • Implicit parameterless constructor (default struct)
    {{ As a C# struct, Orphan has an implicit default constructor. If you need a convenience constructor you can add one in your own code when creating Orphan instances (e.g. new Orphan { m_Composition = someEntity }). }}

Methods

  • None.
    {{ No methods are defined on this struct. Behaviour around Orphan instances is implemented in systems that read/write this component. }}

Usage Example

// Add an Orphan component to an existing entity using EntityManager
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity myEntity = /* existing entity */;
Entity compositionEntity = /* some composition entity */;

// Direct add
em.AddComponentData(myEntity, new Game.Net.Orphan { m_Composition = compositionEntity });

// Or, from a system using EntityCommandBuffer (safe during jobs)
var ecb = new EntityCommandBuffer(Unity.Collections.Allocator.Temp);
ecb.AddComponent(myEntity, new Game.Net.Orphan { m_Composition = compositionEntity });
ecb.Playback(em);
ecb.Dispose();

// Querying in a SystemBase
Entities
    .WithAll<Game.Net.Orphan>()
    .ForEach((Entity e, in Game.Net.Orphan orphan) =>
    {
        Entity comp = orphan.m_Composition;
        // handle orphaned relationship...
    }).Schedule();

{{ Notes: - When modifying components inside jobs, prefer EntityCommandBuffer to perform structural changes. - Because this component implements IEmptySerializable (game serialization marker), the game may include it in save/load flows — ensure referenced composition entities are handled appropriately during serialization. - Validate that m_Composition refers to a valid entity before using it (it may be destroyed). }}