Skip to content

Game.Agents.HasJobSeeker

Assembly: Game
Namespace: Game.Agents

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable, IEnableableComponent

Summary: HasJobSeeker is an ECS component used to mark an entity as a job seeker. It stores a reference to the seeker entity and a frame index indicating the last time this entity looked for a job. The component implements ISerializable to persist those values and gates reading/writing of fields based on serialized-data version flags (Version.seekerReferences and Version.findJobOptimize). As an enableable component it can be enabled/disabled on entities to control whether the entity participates in job-seeking logic.


Fields

  • public Entity m_Seeker This is an Entity reference to the job seeker (typically the agent or a related helper entity). The field is serialized/deserialized only when the reader.context.version is at least Version.seekerReferences. When deserializing older save-data that predates seeker references, this field will remain at its default value (Entity.Null) unless set at runtime.

  • public uint m_LastJobSeekFrameIndex Stores the frame index (uint) of the last frame when this entity attempted to find a job. This is used for optimizations (to avoid repeated searches every frame). The value is serialized/deserialized only when reader.context.version >= Version.findJobOptimize; older save-data will not contain this value.

Properties

  • This type does not expose any C# properties; it only contains the two public fields above and implements serialization through explicit methods.

Constructors

  • public HasJobSeeker()
    Struct default constructor (provided by C#). Default values:
  • m_Seeker = Entity.Null
  • m_LastJobSeekFrameIndex = 0 You can initialize values inline when adding the component to an entity.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component data to the given writer in the order:
  • m_Seeker (Entity)
  • m_LastJobSeekFrameIndex (uint)
    Note: The Serialize implementation writes both fields unconditionally. Compatibility is handled during Deserialize by checking reader.context.version.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads component data from the reader using version gates:

  • If reader.context.version >= Version.seekerReferences: reads m_Seeker.
  • If reader.context.version >= Version.findJobOptimize: reads m_LastJobSeekFrameIndex. This ensures backward compatibility with saves created before those fields existed.

Usage Example

// Example: add/initialize HasJobSeeker on an entity (EntityManager API shown conceptually)
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity agentEntity = /* entity representing the agent */;

// Create and add the component
HasJobSeeker seekerComp = new HasJobSeeker {
    m_Seeker = agentEntity,            // refer to the agent or associated seeker entity
    m_LastJobSeekFrameIndex = 0u       // not yet searched
};
em.AddComponentData(agentEntity, seekerComp);

// Example: later — update last seek frame
HasJobSeeker current = em.GetComponentData<HasJobSeeker>(agentEntity);
current.m_LastJobSeekFrameIndex = (uint)currentFrameIndex;
em.SetComponentData(agentEntity, current);

// Example: enable/disable the component (enableable component API)
em.SetComponentEnabled<HasJobSeeker>(agentEntity, true);  // enable job seeking
em.SetComponentEnabled<HasJobSeeker>(agentEntity, false); // disable job seeking

Notes: - Always consider save-version compatibility: Deserialize reads fields only when the saved data's version includes them. - Because this type is an IComponentData struct, use the ECS APIs (EntityManager, systems) to add, read, update, and enable/disable it, rather than treating it like a regular reference type.