Skip to content

Game.Citizens.Followed

Assembly:
Namespace: Game.Citizens

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Followed is a small ECS component used by the citizen systems to mark an entity as being "followed" and to store a simple follow-related state. It holds an unsigned integer priority (m_Priority) and a boolean (m_StartedFollowingAsChild). The type implements custom binary serialization/deserialization and uses version checks during deserialization to remain compatible with older save formats.


Fields

  • public uint m_Priority
    This field stores a priority value for the follow relationship. It is written first during serialization. Default is 0. During deserialization it is only read if the save version is >= Version.localizationIndex; otherwise it remains at the default.

  • public bool m_StartedFollowingAsChild
    A boolean flag indicating whether following started while the entity was a child. It is written second during serialization. During deserialization it is only read if the save version is >= Version.stalkerAchievement; otherwise it remains at the default (false).

Properties

  • This struct exposes no C# properties; only public fields are used.

Constructors

  • public Followed()
    No explicit constructor is defined — the default parameterless struct constructor is used, initializing m_Priority to 0 and m_StartedFollowingAsChild to false.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes fields to the provided writer in a fixed order:
  • Writes m_Priority (uint)
  • Writes m_StartedFollowingAsChild (bool)

The writer type must implement IWriter.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads fields from the provided reader with version checks to support backward compatibility:
  • If reader.context.version >= Version.localizationIndex, reads m_Priority.
  • If reader.context.version >= Version.stalkerAchievement, reads m_StartedFollowingAsChild.

If the saved data is from an older version where these fields were not present, the corresponding fields remain at their default values. The reader type must implement IReader and provide a context.version value.

Usage Example

// Creating an entity with the Followed component and setting fields:
var entity = entityManager.CreateEntity(typeof(Game.Citizens.Followed));
var followed = new Game.Citizens.Followed {
    m_Priority = 3u,
    m_StartedFollowingAsChild = false
};
entityManager.SetComponentData(entity, followed);

// In systems the component can be queried in a ComponentSystem or SystemBase:
Entities.ForEach((ref Game.Citizens.Followed f) =>
{
    // use f.m_Priority, f.m_StartedFollowingAsChild
}).Schedule();

{{ - Notes: - Serialization order is important: m_Priority then m_StartedFollowingAsChild. - The version checks reference Version.localizationIndex and Version.stalkerAchievement constants (defined elsewhere in the codebase). Ensure those version thresholds match the intended save-format compatibility requirements. - Because this is a struct (IComponentData), it is blittable and cheap to store per-entity. }}