Game.Objects.Aligned
Assembly: Assembly-CSharp
Namespace: Game.Objects
Type: struct
Base: System.ValueType (implements IComponentData, IQueryTypeParameter, ISerializable)
Summary: A small ECS component used to mark an entity as "aligned" to a particular sub-object index. Stores a ushort sub-object index and supports the game's custom serialization via Colossal.Serialization.Entities. This component is suitable for attaching to entities that need to reference or snap to a specific sub-part of a larger object (for example, sub-objects of a composite building or prop).
Fields
public ushort m_SubObjectIndex
Stores the index of the sub-object this entity is aligned to. Range is 0..65535 (ushort). Use this field to identify which sub-object the entity should reference or snap to when resolving alignment. Default value when not set is 0.
Properties
- This type has no properties. It exposes a single public field and implements the necessary interfaces for ECS use and serialization.
Constructors
public Aligned(ushort subObjectIndex)
Creates a new Aligned component with the given sub-object index. Use this to initialize the component when adding it to an entity (e.g., EntityManager.AddComponentData(entity, new Aligned(index));).
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the m_SubObjectIndex value to the provided writer. Used by the game's serialization system (Colossal.Serialization.Entities) to persist component state. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads m_SubObjectIndex from the provided reader. Used by the game's deserialization system to restore the component state when loading saved data.
Implementation notes:
- Both Serialize and Deserialize operate on a single ushort value, so they are lightweight and safe for frequent use.
- The component implements IQueryTypeParameter, enabling use in query-building APIs (e.g., Entities.WithAll
Usage Example
// Adding the component to an entity with a specific sub-object index
var aligned = new Aligned(5); // align to sub-object index 5
entityManager.AddComponentData(entity, aligned);
// Querying entities that have the Aligned component
Entities
.WithAll<Aligned>()
.ForEach((Entity e, ref Aligned a) =>
{
// use a.m_SubObjectIndex to resolve alignment/position logic
});
// The Serialize/Deserialize methods are used by the game's save/load pipeline automatically.
// No manual call is typically required unless implementing a custom save path.
[Preserve]
protected void ExampleInit()
{
// Example runtime initialization
var e = entityManager.CreateEntity();
entityManager.AddComponentData(e, new Aligned(2));
}