Skip to content

Game.Objects.Attachment

Assembly: Assembly-CSharp
Namespace: Game.Objects

Type: struct

Base: System.ValueType (implements Unity.Entities.IComponentData, IQueryTypeParameter, Colossal.Serialization.Entities.IEmptySerializable)

Summary:
Represents a simple ECS component that stores a reference to another entity that this entity is "attached" to. Commonly used to express parent/child or attachment relationships between entities (for example, an object attached to a vehicle or building). Because it implements IComponentData it is a Unity ECS component; the IQueryTypeParameter and IEmptySerializable interfaces are marker/interop interfaces used by the game and its serialization/querying systems.


Fields

  • public Unity.Entities.Entity m_Attached
    Holds the Entity that this entity is attached to. If no attachment exists this should be Entity.Null. This is a plain value-type entity reference (cheap to copy). To change attachment at runtime, set or replace this component via the EntityManager or relevant ECS system APIs.

Properties

  • None.
    This component exposes only a public field; there are no properties defined on the struct.

Constructors

  • public Attachment(Unity.Entities.Entity attached)
    Initializes the Attachment component with the provided entity reference. Example use: new Attachment(attachedEntity) where attachedEntity is an Entity value (or Entity.Null if intentionally empty).

Methods

  • None.
    There are no methods defined on this struct. Behavior is provided by systems that read/write this component.

Usage Example

// Add an attachment using the EntityManager
var entityManager = Unity.Entities.World.DefaultGameObjectInjectionWorld.EntityManager;
Entity parent = /* some entity */;
Entity child = /* some entity to attach */;

// Attach child to parent (store child in parent's Attachment component)
entityManager.AddComponentData(parent, new Game.Objects.Attachment(child));

// Later, update attachment (detach)
entityManager.SetComponentData(parent, new Game.Objects.Attachment(Unity.Entities.Entity.Null));

// Or remove the Attachment component entirely
entityManager.RemoveComponent<Game.Objects.Attachment>(parent);

// Example inside a SystemBase:
protected override void OnUpdate()
{
    var em = EntityManager;
    Entities
        .WithNone<Game.Objects.Attachment>()
        .ForEach((Entity e, in SomeDriverComponent driver) =>
        {
            // determine an entity to attach (example)
            Entity attachTo = driver.TargetEntity;
            if (attachTo != Entity.Null)
            {
                em.AddComponentData(e, new Game.Objects.Attachment(attachTo));
            }
        }).WithoutBurst().Run();
}

Additional notes: - Check for Entity.Null to test whether an attachment is present. - Because this is a simple value container, concurrency/atomic concerns are the same as other ECS component writes — update via proper ECS APIs (EntityManager, ComponentDataFromEntity, or in-system SetComponentData/AddComponentData) respecting safety rules (main thread / burst / job safety as applicable). - IEmptySerializable is a game-specific serialization marker; the field will be handled by the game's serialization pipeline according to that contract.