Game.Buildings.ServiceUpgrade
Assembly: Game
Namespace: Game.Buildings
Type: struct
Base: System.ValueType
Summary:
ServiceUpgrade is an empty/tag component used with Unity.Entities (DOTS) in the Cities: Skylines 2 codebase. It is declared with explicit StructLayout(Size = 1) and implements IComponentData, IQueryTypeParameter and IEmptySerializable. As an empty struct it is intended to act as a marker/tag on entities (for example to mark buildings that are eligible for or undergoing a "service upgrade") and to be compatible with the game's serialization and ECS query systems.
Fields
- This struct declares no managed instance fields. Additional notes:
- The [StructLayout(LayoutKind.Sequential, Size = 1)] attribute forces the struct's size to be 1 byte even though it has no fields. This is commonly done to ensure a non-zero native size for interop, alignment, or serialization requirements.
- No backing data is stored in this type — it functions purely as a marker/tag component.
Properties
- This type defines no properties.
Constructors
- public ServiceUpgrade() (implicit default) This struct has the default parameterless value-type constructor (implicitly provided by C#). Creating an instance is effectively a no-op because the type carries no fields.
Methods
- This type declares no methods. Implementations and interfaces of interest:
- IComponentData — marks this type as a data component usable with Unity's ECS.
- IQueryTypeParameter — allows the type to be used directly in queries / EntityQuery constructions in some helper APIs.
- IEmptySerializable — a Colossal/serialization marker indicating that the component should be treated as an empty-serializable type by the game's serializer.
Usage Example
// Add the tag to an entity (EntityManager API)
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var archetype = entityManager.CreateArchetype(typeof(ServiceUpgrade), typeof(SomeOtherComponent));
var entity = entityManager.CreateEntity(archetype);
// Or add the tag to an existing entity
entityManager.AddComponentData(entity, new ServiceUpgrade());
// Querying for entities that have the tag (in a SystemBase)
public partial class MySystem : SystemBase
{
protected override void OnUpdate()
{
// Run logic for entities that have the ServiceUpgrade tag
Entities
.WithAll<ServiceUpgrade>()
.ForEach((ref SomeOtherComponent comp) =>
{
// handle upgrade-related logic here
})
.ScheduleParallel();
}
}
// Building an EntityQuery explicitly
var query = entityManager.CreateEntityQuery(ComponentType.ReadOnly<ServiceUpgrade>());
var count = query.CalculateEntityCount();
Notes: - Because ServiceUpgrade carries no data, it is most useful as a boolean/tag: presence means "true," absence means "false." - The StructLayout(Size = 1) ensures the component has a concrete non-zero size for serialization/interop, despite being empty.