Skip to content

Game.Agents.PropertySeeker

Assembly: Assembly-CSharp
Namespace: Game.Agents

Type: struct

Base: Implements IComponentData, IQueryTypeParameter, ISerializable, IEnableableComponent

Summary: PropertySeeker is an ECS component (value type) used by agent entities to track property-seeking state. It stores references to the current target property and the best found property, a score for the best candidate, and the frame when the last property search happened. The struct implements custom serialization to support save/load and version compatibility with older save formats.


Fields

  • public Entity m_TargetProperty Holds the Entity reference to the property the agent is currently targeting (the property the agent is trying to move into or evaluate).

  • public Entity m_BestProperty Holds the Entity reference to the best candidate property found so far by the agent’s search routine.

  • public float m_BestPropertyScore A numeric score representing how desirable the m_BestProperty is for this agent. Higher values indicate better matches according to the agent’s evaluation criteria.

  • public uint m_LastPropertySeekFrame Stores the simulation frame index when this agent last performed a property-seeking operation. Used to avoid doing frequent re-searches each frame and for deterministic behavior across saves/loads (see Deserialize behavior below).

Properties

  • This type defines no C# properties. All data is exposed as public fields.

Constructors

  • public PropertySeeker()
    Structs have an implicit parameterless constructor that zero-initializes fields. No explicit constructors are defined in this type.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component state to the provided writer in the following order:
  • m_TargetProperty (Entity)
  • m_BestProperty (Entity)
  • m_BestPropertyScore (float)
  • m_LastPropertySeekFrame (uint)
    This method is called during save operations to persist the component state.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the component state from the provided reader in the same order as Serialize. For the m_LastPropertySeekFrame field the method performs a version check:

  • If reader.context.format.Has(FormatTags.HomelessAndWorkerFix) is true, it reads a uint into m_LastPropertySeekFrame (newer save format).
  • Otherwise it reads a single byte and discards it (older save format used a byte placeholder).
    This conditional logic ensures backward compatibility with older save formats that did not store a full uint for the last seek frame.

Usage Example

// Example: attaching and updating a PropertySeeker component on an agent entity
// (requires Unity.Entities world and EntityManager available)

var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

// Create an agent entity (example; actual archetype depends on the mod/system)
Entity agent = entityManager.CreateEntity();

// Add or set the PropertySeeker component
PropertySeeker seeker = new PropertySeeker
{
    m_TargetProperty = Entity.Null,
    m_BestProperty = Entity.Null,
    m_BestPropertyScore = 0f,
    m_LastPropertySeekFrame = 0u
};
entityManager.AddComponentData(agent, seeker);

// Later, a system can read/update the component:
seeker = entityManager.GetComponentData<PropertySeeker>(agent);
seeker.m_TargetProperty = somePropertyEntity;
seeker.m_BestProperty = candidatePropertyEntity;
seeker.m_BestPropertyScore = 12.5f;
seeker.m_LastPropertySeekFrame = (uint)SimulationManager.instance.m_currentFrameIndex;
entityManager.SetComponentData(agent, seeker);

// Save/load handled by game serialization; Serialize/Deserialize are invoked by the engine's writer/reader.

Additional notes: - Because this is an IEnableableComponent, systems can enable/disable the component per-entity without removing it. - The Deserialize method contains explicit compatibility handling for the FormatTags.HomelessAndWorkerFix flag — when creating custom serializers or readers, ensure the reader.context.format exposes similar flags if you need to interoperate with the game's save format.