Skip to content

Game.Prefabs.UnlockOnBuild

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
UnlockOnBuild is a prefab component that links a prefab to one or more ObjectBuiltRequirementPrefab unlock entries. When the prefab is initialized, it writes references to those unlock prefabs into a DynamicBuffer on the prefab entity so the game knows which unlock requirements should be granted/considered when this object is built. This component also opts out of normal unlock-dependency resolution by overriding ignoreUnlockDependencies to true.


Fields

  • public ObjectBuiltRequirementPrefab[] m_Unlocks
    Holds the list of ObjectBuiltRequirementPrefab references that this prefab will unlock/associate with. During LateInitialize each entry is resolved to an Entity and added to the UnlockOnBuildData buffer.

Properties

  • public override bool ignoreUnlockDependencies => true
    This component overrides the base property to return true, indicating that it should ignore unlock-dependency resolution (i.e., the component does not participate in being blocked by unlock dependencies when resolving prefab unlock order).

Constructors

  • public UnlockOnBuild()
    Default constructor (implicit). No custom construction logic exists in the source; initialization happens in LateInitialize.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the runtime component type required by this prefab. Implementation:
  • Adds ComponentType.ReadWrite<UnlockOnBuildData>() to the set, ensuring the prefab entity will carry the corresponding buffer component.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Empty implementation. This component does not add fixed archetype components here (it uses a dynamic buffer added in GetPrefabComponents instead).

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Collects prefab dependencies required by this component. Implementation:

  • Calls base.GetDependencies(prefabs).
  • Iterates m_Unlocks and adds each referenced ObjectBuiltRequirementPrefab to the prefabs list so those prefabs are treated as dependencies.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Performs runtime initialization on the prefab entity after it exists in the EntityManager. Implementation details:

  • Calls base.LateInitialize(entityManager, entity).
  • Retrieves the PrefabSystem from the entityManager.World (GetExistingSystemManaged<PrefabSystem>()).
  • Gets the DynamicBuffer for the entity.
  • Iterates m_Unlocks, resolves each ObjectBuiltRequirementPrefab to its runtime Entity via PrefabSystem.GetEntity(prefab), and adds an UnlockOnBuildData element with that Entity into the buffer.
  • Result: the prefab entity has a buffer of UnlockOnBuildData entries pointing to the entities representing the unlock requirements.

Notes / Behavior: - Ensure m_Unlocks is non-null before using; the code assumes m_Unlocks.Length usage. - The PrefabSystem must be present in the World; if it is missing, LateInitialize will throw or fail to resolve entities. - UnlockOnBuildData is expected to be a buffer element type with a field (m_Entity) used to store the resolved Entity.

Usage Example

// Example of what LateInitialize does internally (simplified)
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
    base.LateInitialize(entityManager, entity);
    var prefabSystem = entityManager.World.GetExistingSystemManaged<PrefabSystem>();
    var buffer = entityManager.GetBuffer<UnlockOnBuildData>(entity);
    for (int i = 0; i < m_Unlocks.Length; i++)
    {
        Entity unlockedEntity = prefabSystem.GetEntity(m_Unlocks[i]);
        buffer.Add(new UnlockOnBuildData { m_Entity = unlockedEntity });
    }
}

Additional tips: - Use this component on building, net, static object or extension prefabs (the ComponentMenu attribute indicates intended usage). - If you add or change m_Unlocks in a prefab authoring tool, the corresponding UnlockOnBuildData buffer will be populated at initialization so the game systems that check build-time unlocks can read them.