Game.Prefabs.Climate.SeasonFilter
Assembly: Assembly-CSharp (game code)
Namespace: Game.Prefabs.Climate
Type: class
Base: ComponentBase
Summary:
SeasonFilter is a prefab/component used to link a prefab to one or more SeasonPrefab instances. At initialization it records the entity references of those season prefabs into the entity's ObjectRequirementElement dynamic buffer so other systems can query the season-related requirements for this prefab. It also declares the required component type so the buffer exists on the prefab entity.
Fields
public SeasonPrefab[] m_Seasons
Holds references to one or more SeasonPrefab prefabs. These are the seasons that this filter will register as object requirements on the prefab's entity during LateInitialize. This field is exposed on the component and typically set in prefab data / inspector.
Properties
- (none public)
Constructors
public SeasonFilter()
Default parameterless constructor (inherited behavior). No custom construction logic is defined in the source.
Methods
public override void GetDependencies(List<PrefabBase> prefabs)
Adds referenced SeasonPrefab instances to the provided dependency list. Implementation:- Calls base.GetDependencies(prefabs).
- Iterates over m_Seasons and calls prefabs.Add(m_Seasons[i]) for each referenced season prefab.
-
Ensures the referenced season prefabs are included in build/pack/loading as dependencies.
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the component type required by this prefab so the entity will have a DynamicBufferat runtime: -
Adds ComponentType.ReadWrite
() to the components set. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
No archetype components are added by this component (method intentionally empty). -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Populates the prefab entity's ObjectRequirementElement buffer with entries for each referenced SeasonPrefab: - Retrieves the PrefabSystem from the entityManager.World.
- Gets the DynamicBuffer
for the provided entity (relies on GetPrefabComponents having declared the component). - Captures the current buffer.Length into a local
length
variable. - For each SeasonPrefab in m_Seasons, resolves its Entity via PrefabSystem.GetEntity(seasonPrefab) and calls buffer.Add(new ObjectRequirementElement(entityOfSeason, length)).
- Note: each added ObjectRequirementElement is created with the same index value (
length
) — this matches the source behavior.
Important implementation notes: - LateInitialize assumes ObjectRequirementElement buffer exists on the entity. If GetPrefabComponents is not respected or the buffer is removed, entityManager.GetBuffer will throw. - PrefabSystem.GetEntity(seasonPrefab) is used to map the SeasonPrefab reference to its runtime Entity. Ensure referenced SeasonPrefab objects are valid and present in the PrefabSystem. - The code records the initial buffer length into the new entries; if multiple entries are added, they all use the same index value (the original buffer length) — this is the behavior in the source implementation.
Usage Example
// Example: a prefab scriptable setup (pseudo-usage in prefab data) and what LateInitialize does at runtime.
// In prefab data you would set SeasonFilter.m_Seasons = [seasonPrefabSpring, seasonPrefabSummer];
// At runtime, during prefab initialization:
protected override void LateInitialize(EntityManager entityManager, Entity entity)
{
base.LateInitialize(entityManager, entity);
// The SeasonFilter.LateInitialize implementation will:
// - get PrefabSystem
// - get the ObjectRequirementElement buffer on the entity
// - for each SeasonPrefab referenced in m_Seasons, resolve its Entity and add an ObjectRequirementElement(entryEntity, originalBufferLength)
}
Additional tips for modders:
- Make sure SeasonPrefab references are valid and included as dependencies (GetDependencies handles this if the prefab references are set).
- If you expect per-entry different indices, you may need to adjust the source behavior (it stores the same length
value for all added entries).
- Verify that other systems that consume ObjectRequirementElement buffers interpret the stored index value in the intended way.