Skip to content

Game.Agents.MovingAway

Assembly: Assembly-CSharp (main game assembly)
Namespace: Game.Agents

Type: struct

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

Summary:
MovingAway is a lightweight ECS component used to mark an agent that is moving away from a specific target entity. It stores a single Entity reference (m_Target) which represents the object the agent is avoiding or moving away from. The struct implements the game's serialization interfaces so the target reference is persisted in saves and can participate in any serialization-based workflows (export/import, network sync, etc.). The default (uninitialized) value of m_Target is Entity.Null.


Fields

  • public Unity.Entities.Entity m_Target
    Holds the Entity that this agent is moving away from. Typically set to another in-game object (building, vehicle, hazard, etc.). When uninitialized it will be Entity.Null. This field is serialized/deserialized by the struct's ISerializable implementation.

Properties

  • None.
    This component is a plain data struct with a single public field and no properties.

Constructors

  • public MovingAway()
    The default parameterless constructor is provided by the C# compiler for structs. Initialize explicitly when adding to an entity, e.g. new MovingAway { m_Target = targetEntity }.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : Colossal.Serialization.Entities.IWriter
    Writes the m_Target Entity to the provided writer. Used by the game's serialization system to persist this component's data.

  • public void Deserialize<TReader>(TReader reader) where TReader : Colossal.Serialization.Entities.IReader
    Reads an Entity value from the provided reader into m_Target. Used when loading/synchronizing saved component data.

Both methods are simple pass-throughs to the writer/reader and rely on the underlying IWriter/IReader implementations to correctly serialize Entity handles.

Usage Example

// Add or update the component on an entity
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity agent = /* existing agent entity */;
Entity target = /* entity to move away from */;

em.AddComponentData(agent, new Game.Agents.MovingAway { m_Target = target });

// Read the target later in a system
var comp = em.GetComponentData<Game.Agents.MovingAway>(agent);
if (comp.m_Target != Entity.Null)
{
    // Use comp.m_Target for pathfinding, steering, AI decisions, etc.
}

Notes: - Use Unity.Entities queries (e.g., Entities.ForEach, EntityQuery) to find entities with the MovingAway component. - Because this struct implements ISerializable, its Serialize/Deserialize methods will be invoked automatically by the game's save/load pipeline — you normally don't call them directly. - Ensure that referenced entities (m_Target) remain valid for the lifetime they are used; compare against Entity.Null to detect uninitialized or cleared references.