Skip to content

Game.Common.Owner

Assembly: Assembly-CSharp
Namespace: Game.Common

Type: struct

Base: System.ValueType, Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable

Summary:
A lightweight ECS component that stores a reference to an owning Entity. Commonly used to express ownership/parent relationships between entities in the game's Entity Component System. Implements Colossal's serialization interfaces so the owner reference is persisted across save/load cycles.


Fields

  • public Unity.Entities.Entity m_Owner
    Stores the owner Entity reference. This field is written/read by the Serialize/Deserialize implementations to persist the relationship. It is public and can be read or updated directly when manipulating component data.

Properties

  • This struct does not define any properties. It exposes the owner via the public field m_Owner.

Constructors

  • public Owner(Entity owner)
    Initializes a new Owner component with the provided owner Entity, setting m_Owner = owner.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the m_Owner Entity to the provided writer. This method is used by the game's serialization system to save the owner reference.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads an Entity value from the provided reader into m_Owner. This method restores the owner reference when loading saved data.

Usage Example

// Example: assign an owner entity to another entity using EntityManager
using Unity.Entities;
using Game.Common;

void AssignOwner(EntityManager entityManager, Entity ownerEntity, Entity childEntity)
{
    // Ensure the child entity has the Owner component and set it
    var ownerComp = new Owner(ownerEntity);
    if (!entityManager.HasComponent<Owner>(childEntity))
    {
        entityManager.AddComponentData(childEntity, ownerComp);
    }
    else
    {
        entityManager.SetComponentData(childEntity, ownerComp);
    }
}

// The Owner component is serialized by the game's save system automatically
// via the ISerializable implementation; mod code typically doesn't call
// Serialize/Deserialize directly.