Game.Prefabs.PrefabUnlockedRequirementPrefab
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: UnlockRequirementPrefab
Summary:
Prefab class used to define unlocking requirements that depend on other prefabs. When this prefab is initialized it ensures the entity receives the UnlockRequirement and PrefabUnlockedRequirement components/buffers, and it populates the PrefabUnlockedRequirement buffer with references to the entities of the required prefabs (m_RequiredPrefabs). This effectively makes the prefab require the listed prefabs (RequireAll) before it is considered unlocked.
Fields
public PrefabBase[] m_RequiredPrefabs
Array of prefab assets that this prefab requires to be unlocked. During LateInitialize each element is resolved to its Entity via the game's PrefabSystem and stored into the PrefabUnlockedRequirement dynamic buffer on the prefab entity.
Properties
- None declared on this class.
This class relies on overrides from its base class and on populating ECS buffers/components during LateInitialize.
Constructors
public PrefabUnlockedRequirementPrefab()
Default parameterless constructor (implicit if not defined). No custom construction logic in source; Unity/serialization will set m_RequiredPrefabs via the inspector or prefab data.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds required component types for this prefab. Implementation:- Calls base.GetPrefabComponents(components).
-
Adds ComponentType.ReadWrite
() to the provided set so the prefab entity will include the PrefabUnlockedRequirement buffer/component at conversion/creation time. Purpose: declare to the ECS conversion system which components/buffers the resulting entity must have. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Populates runtime ECS buffers for the prefab entity. Implementation details: - Calls base.LateInitialize(entityManager, entity).
- Adds an UnlockRequirement entry to the entity's UnlockRequirement buffer with UnlockFlags.RequireAll (so this prefab requires all listed requirements).
- Obtains the game's PrefabSystem from the entityManager.World and resolves each PrefabBase in m_RequiredPrefabs to its Entity.
- Adds a PrefabUnlockedRequirement entry for each resolved entity to the entity's PrefabUnlockedRequirement dynamic buffer, setting m_Requirement to the resolved entity. Purpose: at initialization time convert the inspector-assigned prefab references into entity references and register them as unlock requirements.
Usage Example
// Typical usage is done by Unity's prefab system and game conversion.
// Example: the engine will call LateInitialize during prefab conversion/initialization.
// You assign required prefabs in the inspector (m_RequiredPrefabs),
// and this class will convert them into PrefabUnlockedRequirement entries.
public class MyPrefab : PrefabUnlockedRequirementPrefab
{
// m_RequiredPrefabs assigned in inspector
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
base.LateInitialize(entityManager, entity);
// After this runs, entity has:
// - an UnlockRequirement entry with UnlockFlags.RequireAll
// - a PrefabUnlockedRequirement buffer listing the entity IDs of required prefabs
}
}
Notes and modding considerations: - m_RequiredPrefabs holds PrefabBase references (asset-level). Those are resolved to Entities at runtime via PrefabSystem.GetEntity. - The code uses RequireAll, meaning all listed prefabs must be unlocked for this prefab to become available. If you need different combine logic you would need to modify the UnlockRequirement flags or buffer entries accordingly. - Ensure the required prefabs are included in the same conversion/world so PrefabSystem.GetEntity can resolve them successfully. If a referenced prefab is missing or not converted, PrefabSystem.GetEntity may return Entity.Null — handle that if you modify behavior.