Game.Objects.UnderConstruction
Assembly: Game
Namespace: Game.Objects
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Component that marks an entity as "under construction". Holds a reference to the new prefab that will replace the current entity, plus construction progress and speed values. The type was previously serialized under the name "Game.Buildings.SetLevel, Game" (see FormerlySerializedAs attribute). Serialization is version-aware and provides sensible defaults for older save versions.
Fields
-
public Entity m_NewPrefab
Reference to the prefab/entity that will replace or become the finished building once construction completes. Serialized first. -
public byte m_Progress
Construction progress stored as a byte. When deserializing from older save versions (pre-constructionProgress), this is defaulted to byte.MaxValue (255). -
public byte m_Speed
Construction speed stored as a byte. When deserializing from older save versions (pre-constructionSpeed), this is defaulted to 50.
Properties
- This type has no properties.
Constructors
public UnderConstruction()
Default (value) constructor generated for the struct. Fields should be explicitly set before use (or set via SetComponentData when adding to an entity).
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes the component in the order: m_NewPrefab, m_Progress, m_Speed. The writer receives each field in that order. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads fields back in the same order. This method checks reader.context.version: - If version >= Version.constructionProgress: reads m_Progress; otherwise sets m_Progress = byte.MaxValue.
- If version >= Version.constructionSpeed: reads m_Speed; otherwise sets m_Speed = 50.
Usage Example
// Create and assign an UnderConstruction component to an entity using EntityManager
var underConstruction = new UnderConstruction
{
m_NewPrefab = somePrefabEntity,
m_Progress = 0, // starting progress
m_Speed = 50 // default speed
};
entityManager.AddComponentData(targetEntity, underConstruction);
// Example: updating progress (pseudo-update)
var uc = entityManager.GetComponentData<UnderConstruction>(targetEntity);
uc.m_Progress += uc.m_Speed; // adjust as appropriate for delta/time
entityManager.SetComponentData(targetEntity, uc);
{{ This struct is used by the game's ECS to mark and track buildings (or other objects) that are mid-construction. Be mindful that progress and speed are stored as bytes; older save compatibility is handled in Deserialize by providing defaults. }}