Skip to content

Game.Prefabs.PlaceholderBuilding

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
A prefab component used by building prefabs to mark them as "placeholder" buildings. This class records the building type and a reference to a zone prefab (if any), declares the runtime component types required for the prefab's entity (PlaceholderBuildingData and a Placeholder marker), and initializes the PlaceholderBuildingData component during LateInitialize. It is exposed in the Unity component menu under "Buildings/".


Fields

  • public const int kStatLevel = 1
    A constant value (1). Likely used by game systems or tooling to indicate the statistic or detail level associated with this prefab or its placeholder status.

  • public BuildingType m_BuildingType
    Enum value specifying the building type for the placeholder. This value is stored into the PlaceholderBuildingData component so systems reading building-type-specific behaviour can use it at runtime.

  • public ZonePrefab m_ZoneType
    Reference to a ZonePrefab used by this placeholder. During LateInitialize this is resolved to an Entity (via PrefabSystem) and stored in PlaceholderBuildingData.m_ZonePrefab; if null, Entity.Null is used.

Properties

  • This class exposes no public properties.

Constructors

  • public PlaceholderBuilding()
    Default public constructor (implicit). No custom construction logic is defined in the source; initialization is handled by the overridden Initialize / LateInitialize methods and by Unity/Engine prefab construction flow.

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Adds any prefab dependencies required by this component. This override adds the referenced m_ZoneType to the provided list so the prefab build system knows to include that zone prefab.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds runtime component types that should be present on the instantiated entity. This method adds ComponentType.ReadWrite() so the entity will carry the data struct representing this placeholder.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds archetype-level components required for entities of this prefab. This method adds ComponentType.ReadWrite() to ensure the entity has the Placeholder marker component in its archetype.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called during prefab initialization. This override calls the base implementation; no additional logic is executed here in the provided source.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Final initialization step executed after other prefabs/systems are available. This method:

  • Calls base.LateInitialize.
  • Retrieves the PrefabSystem from the EntityManager.World.
  • Creates and sets a PlaceholderBuildingData component on the entity, populating:
    • m_Type with m_BuildingType.
    • m_ZonePrefab with the Entity corresponding to m_ZoneType (using PrefabSystem.GetEntity) or Entity.Null if m_ZoneType is null. This resolves prefab references into actual entity handles used at runtime.

Usage Example

// Example of what LateInitialize is doing internally — resolving the zone prefab
// and setting PlaceholderBuildingData on the prefab entity.
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
    base.LateInitialize(entityManager, entity);
    PrefabSystem prefabSystem = entityManager.World.GetExistingSystemManaged<PrefabSystem>();

    entityManager.SetComponentData(entity, new PlaceholderBuildingData
    {
        m_Type = m_BuildingType,
        m_ZonePrefab = (m_ZoneType != null) ? prefabSystem.GetEntity(m_ZoneType) : Entity.Null
    });
}

Additional notes: - The class is decorated with [ComponentMenu("Buildings/", typeof(BuildingPrefab))], making it available in Unity's component menu under Buildings/ when authoring prefabs. - Runtime component types referenced (PlaceholderBuildingData and Placeholder) must exist in the game's ECS codebase; this class only ensures their presence on prefab entities.