Game.Prefabs.ObjectBuiltRequirementPrefab
Assembly: Assembly-CSharp (typical for Cities: Skylines 2 mods)
Namespace: Game.Prefabs
Type: class
Base: UnlockRequirementPrefab
Summary:
Prefab component that represents an unlocking requirement based on a minimum number of a specific built object. This prefab:
- Exposes an inspector field m_MinimumCount to set how many instances of the target object are required.
- Adds the ObjectBuiltRequirementData component type to the prefab's component list.
- During entity initialization, adds an UnlockRequirement buffer entry and writes an ObjectBuiltRequirementData instance with the configured minimum count to the entity.
Fields
public int m_MinimumCount = 1
Integer value serialized on the prefab that specifies the minimum number of objects required to meet this unlock requirement. Default is 1. This value is copied into the ObjectBuiltRequirementData component during LateInitialize.
Properties
- None declared on this class. (The class relies on component data and the behavior inherited from UnlockRequirementPrefab.)
Constructors
public ObjectBuiltRequirementPrefab()
Default parameterless constructor (implicit). Prefab instances are typically created/serialized by Unity; no special construction logic in this class.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the required ECS component types for this prefab. Calls base.GetPrefabComponents(components) and then adds ComponentType.ReadWrite() so the entity will contain the data needed to evaluate the object-built requirement. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Called during prefab-to-entity conversion / initialization. Behavior: - Calls base.LateInitialize(entityManager, entity).
- Adds one UnlockRequirement entry to the entity's UnlockRequirement buffer (constructed with the entity and UnlockFlags.RequireAll).
- Creates an ObjectBuiltRequirementData instance, copies m_MinimumCount into its m_MinimumCount field, and writes it to the entity using entityManager.SetComponentData.
Usage Example
// Example: how this prefab behaves during initialization (logic already implemented inside the prefab):
// The prefab has m_MinimumCount set in the inspector (e.g., 3).
// During conversion, LateInitialize will add an UnlockRequirement buffer entry
// and set ObjectBuiltRequirementData with m_MinimumCount = 3.
[ComponentMenu("Prefabs/Unlocking/", new Type[] { })]
public class ExampleUsage : ObjectBuiltRequirementPrefab
{
// You can override LateInitialize if you need to add additional components or modify behavior:
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
base.LateInitialize(entityManager, entity);
// Additional custom initialization if needed.
// For example, add another requirement or tweak component data.
}
}
Notes and considerations: - This class depends on the ECS types ObjectBuiltRequirementData and UnlockRequirement, and uses UnlockFlags.RequireAll when adding the requirement — ensure those types/flags are available in the modding environment. - Because the prefab writes component data in LateInitialize, any systems that read ObjectBuiltRequirementData should run after prefab initialization.