Game.Simulation.LocalEffectUpdateSystem
Assembly: Assembly-CSharp
Namespace: Game.Simulation
Type: class
Base: GameSystemBase
Summary:
LocalEffectUpdateSystem is a managed ECS system responsible for updating the LocalEffectSystem's search tree with effect provider entities (e.g., buildings or objects that provide local modifiers/effects). It queries entities that are LocalEffectProvider + Efficiency and processes them in a scheduled IJobChunk (UpdateLocalEffectsJob). The job reads transforms, prefab references, installed upgrades and local modifier buffers, computes effect bounds per modifier and updates a NativeQuadTree inside LocalEffectSystem. The system also registers the scheduled job as a local-effect writer with LocalEffectSystem so the effect data is treated as written by that job.
Fields
-
private LocalEffectSystem m_LocalEffectSystem
Holds a reference to the LocalEffectSystem instance in the same World. Used to obtain the search tree (NativeQuadTree) and to register the job as a writer via AddLocalEffectWriter. -
private EntityQuery m_EffectProviderQuery
EntityQuery used to select effect provider entities. The query requires LocalEffectProvider and Efficiency and excludes Signature, Deleted, Destroyed and Temp components. -
private TypeHandle __TypeHandle
Container of ECS type/handle fields (EntityTypeHandle, BufferTypeHandle, ComponentTypeHandle , ComponentTypeHandle , BufferTypeHandle , ComponentLookup , BufferLookup ). Assigned in OnCreateForCompiler and used to obtain runtime-safe handles for scheduling the job.
Nested Types
private struct UpdateLocalEffectsJob : IJobChunk
Burst-compiled job that iterates chunks of effect provider entities and updates the LocalEffectSystem's NativeQuadTree. Key members:- m_SearchTree: NativeQuadTree
— the tree to read/write effect items/bounds. - m_EntityType: EntityTypeHandle — entity array handle.
- m_BuildingEfficiencyType: BufferTypeHandle
— buffer handle to read building efficiency. - m_TransformType: ComponentTypeHandle
— transform component handle. - m_PrefabRefType: ComponentTypeHandle
— prefab reference handle. - m_InstalledUpgradeType: BufferTypeHandle
— installed upgrades buffer handle. - m_PrefabRefData: ComponentLookup
— lookup to resolve upgrade prefab refs to prefab entities. - m_LocalModifierData: BufferLookup
— lookup for prefab-local modifiers buffers.
Important methods:
- Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask): iterates entities in the chunk, builds a temporary NativeList
private struct TypeHandle
Holds the various type/handle fields referenced above and exposes __AssignHandles(ref SystemState state) to populate handles. This is generated helper logic to capture handles in a consistent manner for scheduling jobs.
Properties
- None (the system exposes no public properties)
Constructors
public LocalEffectUpdateSystem()
Default constructor. Marked with [Preserve] on lifecycle methods; constructor exists to satisfy ECS and managed code creation.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns the update interval for this system. Implementation returns 256 indicating the system runs at that interval (frame spacing defined by the engine's scheduling). -
[Preserve] protected override void OnCreate()
Initializes the system: - Acquires the LocalEffectSystem via base.World.GetOrCreateSystemManaged
() and stores it in m_LocalEffectSystem. - Builds m_EffectProviderQuery to select LocalEffectProvider + Efficiency and exclude Signature/Deleted/Destroyed/Temp.
-
Calls RequireForUpdate(m_EffectProviderQuery) so the system only updates when query has matching entities.
-
[Preserve] protected override void OnUpdate()
Schedules the UpdateLocalEffectsJob: - Calls m_LocalEffectSystem.GetSearchTree(readOnly: false, out dependencies) to obtain a writable NativeQuadTree and any dependencies it carries.
- Constructs and schedules UpdateLocalEffectsJob via JobChunkExtensions.Schedule over m_EffectProviderQuery, combining base.Dependency and the obtained dependencies.
- Registers the scheduled job with m_LocalEffectSystem.AddLocalEffectWriter(jobHandle).
-
Sets base.Dependency = jobHandle so the dependency chain is maintained.
-
[MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
Compiler-generated helper: prepares any EntityQueryBuilder usage (here it only creates and disposes a builder placeholder). -
protected override void OnCreateForCompiler()
Compiler helper that calls __AssignQueries and calls __TypeHandle.__AssignHandles(ref base.CheckedStateRef) to populate the stored type handles for later use when scheduling jobs. -
[Preserve] public LocalEffectUpdateSystem()
Public parameterless constructor (duplicate listed for completeness).
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Acquire LocalEffectSystem and build query for effect providers
m_LocalEffectSystem = base.World.GetOrCreateSystemManaged<LocalEffectSystem>();
m_EffectProviderQuery = GetEntityQuery(
ComponentType.ReadOnly<LocalEffectProvider>(),
ComponentType.ReadOnly<Efficiency>(),
ComponentType.Exclude<Signature>(),
ComponentType.Exclude<Deleted>(),
ComponentType.Exclude<Destroyed>(),
ComponentType.Exclude<Temp>()
);
RequireForUpdate(m_EffectProviderQuery);
}
[Preserve]
protected override void OnUpdate()
{
// Acquire the NativeQuadTree writer and schedule the chunk job that updates local effects
JobHandle searchTreeDeps;
var searchTree = m_LocalEffectSystem.GetSearchTree(readOnly: false, out searchTreeDeps);
var job = new UpdateLocalEffectsJob
{
m_SearchTree = searchTree,
m_EntityType = InternalCompilerInterface.GetEntityTypeHandle(ref __TypeHandle.__Unity_Entities_Entity_TypeHandle, ref base.CheckedStateRef),
m_BuildingEfficiencyType = InternalCompilerInterface.GetBufferTypeHandle(ref __TypeHandle.__Game_Buildings_Efficiency_RO_BufferTypeHandle, ref base.CheckedStateRef),
m_TransformType = InternalCompilerInterface.GetComponentTypeHandle(ref __TypeHandle.__Game_Objects_Transform_RO_ComponentTypeHandle, ref base.CheckedStateRef),
m_PrefabRefType = InternalCompilerInterface.GetComponentTypeHandle(ref __TypeHandle.__Game_Prefabs_PrefabRef_RO_ComponentTypeHandle, ref base.CheckedStateRef),
m_InstalledUpgradeType = InternalCompilerInterface.GetBufferTypeHandle(ref __TypeHandle.__Game_Buildings_InstalledUpgrade_RO_BufferTypeHandle, ref base.CheckedStateRef),
m_PrefabRefData = InternalCompilerInterface.GetComponentLookup(ref __TypeHandle.__Game_Prefabs_PrefabRef_RO_ComponentLookup, ref base.CheckedStateRef),
m_LocalModifierData = InternalCompilerInterface.GetBufferLookup(ref __TypeHandle.__Game_Prefabs_LocalModifierData_RO_BufferLookup, ref base.CheckedStateRef)
};
JobHandle handle = JobChunkExtensions.Schedule(job, m_EffectProviderQuery, JobHandle.CombineDependencies(base.Dependency, searchTreeDeps));
m_LocalEffectSystem.AddLocalEffectWriter(handle);
base.Dependency = handle;
}
Notes and tips: - The UpdateLocalEffectsJob is Burst-compiled for performance and uses temporary NativeList storage per chunk; ensure that any modifications to that logic respect burst-compatible types and allocation patterns. - LocalEffectSystem.GetSearchTree and AddLocalEffectWriter are critical to safe multi-threaded access to the NativeQuadTree. Always obtain the tree with the out dependencies and register the job as a writer. - The system relies on prefab LocalModifierData buffers and InstalledUpgrade buffers to build the effective list of modifiers; changes to prefab/modifier storage may require updating this system.