Skip to content

Game.Citizens.MailSender

Assembly:
Game (inferred from file path; actual assembly name may vary depending on project build) Namespace: Game.Citizens

Type: struct (value type)

Base: Implements: - Unity.Entities.IComponentData - Unity.Entities.IQueryTypeParameter - Colossal.Serialization.Entities.ISerializable - Unity.Entities.IEnableableComponent

Summary: A lightweight ECS component that stores the number of mail items (ushort) to send. It is serializable via the Colossal.Serialization system and can be enabled/disabled as an enableable component. Typically used to tag or provide data for entities that will perform mail-sending behavior in the Cities: Skylines 2 modding environment.


Fields

  • public ushort m_Amount This field holds the amount/quantity of mail associated with the component. It is publicly accessible and is the only stored value in this struct. The value is serialized/deserialized by the implemented ISerializable methods.

  • {{ YOUR_INFO }} Additional notes: The choice of ushort limits amounts to 0..65535, which is usually sufficient for counts such as mail items while saving a small memory footprint.

Properties

  • This struct does not declare any C# properties. {{ YOUR_INFO }} Note: Being an IEnableableComponent, the component instance can be enabled/disabled through the EntityManager (or equivalent API) even though it exposes no explicit properties.

Constructors

  • public MailSender(ushort amount) Creates a new MailSender instance and sets m_Amount to the provided value.

{{ YOUR_INFO }} Example intent: Use this constructor when creating and assigning the component to an entity so the entity carries the initial mail count.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter Writes the m_Amount value into the provided writer. This is called by Colossal.Serialization when saving component state.

{{ YOUR_INFO }} Implementation detail: The method delegates to writer.Write(m_Amount). The writer must know how to encode a ushort.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader Reads the m_Amount value from the provided reader. This is used when loading component state.

{{ YOUR_INFO }} Implementation detail: The reader.Read(out m_Amount) populates the field from serialized data. Ensure the reader's state matches what Serialize wrote.

Usage Example

// Add the component to an entity with an initial amount
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var entity = entityManager.CreateEntity();
// give the entity 10 mail items
entityManager.AddComponentData(entity, new Game.Citizens.MailSender(10));

// Later, read or update:
var mail = entityManager.GetComponentData<Game.Citizens.MailSender>(entity);
ushort currentAmount = mail.m_Amount;

// Update amount and write back:
mail.m_Amount = (ushort)(currentAmount + 5);
entityManager.SetComponentData(entity, mail);

// Serialization is handled by the Colossal.Serialization system during save/load.
// Manually (conceptual) usage:
var writer = /* obtain IWriter from serialization context */;
var ms = new Game.Citizens.MailSender(7);
ms.Serialize(writer);

// And during load:
var reader = /* obtain IReader from deserialization context */;
var loaded = new Game.Citizens.MailSender();
loaded.Deserialize(reader);

{{ YOUR_INFO }} Notes: - Because this struct implements IEnableableComponent, you can enable/disable the component on an entity using the appropriate EntityManager methods (e.g., EntityManager.SetComponentEnabled(entity, true/false)) when supported by your ECS version. - The component is minimal by design—expand with additional fields or companion systems if you need more complex mail state or behavior.