Skip to content

Game.Citizens.HasSchoolSeeker

Assembly: Assembly-CSharp
Namespace: Game.Citizens

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary: Component used by the ECS to store a reference to a "seeker" Entity that is looking for a school. The struct is serializable and uses versioned deserialization so older save formats that predate seeker references will not attempt to read the field. Typical usage is to attach this component to an entity to record which citizen/agent Entity is seeking a school.


Fields

  • public Unity.Entities.Entity m_Seeker Holds the Entity reference for the seeker (e.g., a citizen or agent Entity that is searching for a school). Default value is Entity.Null when not set. The field is persisted by the ISerializable implementation but only read back during deserialization if the saved data version supports seeker references (see Deserialize).

Properties

  • (none)

Constructors

  • (implicit) public HasSchoolSeeker()
    No explicit constructor is defined. The default struct constructor initializes m_Seeker to its default value (Entity.Null).

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the m_Seeker Entity reference to the provided writer. This is invoked by the game's serialization pipeline to persist the component's data.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads m_Seeker from the provided reader only if the reader's context version is at or above Version.seekerReferences. The method uses a ref to the field when calling reader.Read to avoid unnecessary copying. If the saved data is older than the seekerReferences version, m_Seeker remains at its default (Entity.Null).

Notes: - Implements version-aware deserialization to maintain backwards compatibility with saves created before seeker references were serialized. - Because this is a plain struct component, care must be taken when copying/manipulating it (value semantics). Ensure Entity validity (not destroyed) before using the stored Entity reference.

Usage Example

// Add the component to an entity and assign a seeker Entity
Entity seekerEntity = /* obtain seeker entity */;
Entity targetEntity = entityManager.CreateEntity();
entityManager.AddComponentData(targetEntity, new Game.Citizens.HasSchoolSeeker { m_Seeker = seekerEntity });

// Read the seeker back later
var comp = entityManager.GetComponentData<Game.Citizens.HasSchoolSeeker>(targetEntity);
Entity storedSeeker = comp.m_Seeker;
if (storedSeeker != Entity.Null)
{
    // Use storedSeeker (ensure it is still valid in the world)
}