Game.Achievements.EventAchievementTrackingData
Assembly: Game
Namespace: Game.Achievements
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary: EventAchievementTrackingData is a small value-type ECS component used to track an achievement-related event for an entity. It stores the frame the event tracking started and the achievement identifier. It implements Colossal's serialization interfaces so instances can be persisted and reconstructed via IWriter/IReader, and implements IQueryTypeParameter so it can be used in ECS queries.
Fields
-
public uint m_StartFrame
Start frame (frame index) when this achievement event started being tracked. Typically set to Time.frameCount or equivalent when the event occurs. -
public AchievementId m_ID
Wrapper type representing the achievement identifier. Internally the code serializes/deserializes this as an int (m_ID.id).
Properties
- (none) This struct does not declare properties. It exposes its data as public fields and relies on the implemented interfaces for serialization/query usage.
Constructors
- default (implicit) constructor As a struct, EventAchievementTrackingData has the implicit parameterless constructor which zero-initializes fields. You can also construct it with an object initializer, e.g.: new EventAchievementTrackingData { m_StartFrame = (uint)Time.frameCount, m_ID = new AchievementId(42) };
Methods
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads state from the provided reader in the same order as Serialize writes it. Implementation details:- Reads a uint into m_StartFrame.
-
Reads an int into a local and uses it to construct m_ID (new AchievementId(value)). This method expects the source stream to have the same layout (uint, int) and does not perform explicit validation or error handling.
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component state to the provided writer in the following order: - writes m_StartFrame as a uint
- writes m_ID.id as an int Consumers should write/read in the same order to ensure correct round-trip serialization.
Usage Example
// Example usage patterns (IWriter/IReader are provided by Colossal.Serialization.Entities)
// Creating and attaching to an entity as a component
var data = new EventAchievementTrackingData
{
m_StartFrame = (uint)UnityEngine.Time.frameCount,
m_ID = new AchievementId(123) // 123 is the achievement integer id
};
// entityManager.AddComponentData(entity, data); // example, depends on ECS usage
// Serializing to a writer (pseudo-code)
IWriter writer = /* obtain writer from serialization system */;
data.Serialize(writer);
// Deserializing from a reader (pseudo-code)
IReader reader = /* obtain reader to read the same data */;
var loadedData = new EventAchievementTrackingData();
loadedData.Deserialize(reader);
{{ Additional info }} - Because this is an IComponentData, prefer using it in ECS systems for per-entity tracking rather than storing global state. - Ensure serializer and deserializer use the same ordering/types (uint then int) to avoid data corruption. - AchievementId is serialized as an int; if AchievementId's internal representation changes, update these methods accordingly.