Skip to content

Game.UI.InGame.UIHighlightSystem

Assembly:
Assembly-CSharp.dll

Namespace:
Game.UI.InGame

Type:
class

Base:
GameSystemBase, IPreDeserialize

Summary:
UIHighlightSystem is an ECS System that finds recently unlocked prefab entities (entities with the Unlock component) and schedules a job to add the UIHighlight component to the unlocked prefab entity and related UI entities (its group and the group's menu) or to the prefab alone for toolbar groups. The system uses an EndFrameBarrier to create an EntityCommandBuffer and schedules the work as a JobChunk (HighlightJob). It also implements IPreDeserialize to clear any UIHighlight components before deserialization and supports skipping its first update pass.


Fields

  • private EndFrameBarrier m_EndFrameBarrier
    Used to create an EntityCommandBuffer for adding UIHighlight components from a background job. The barrier ensures command buffer playback at the correct frame boundary.

  • private EntityQuery m_UnlockedPrefabQuery
    EntityQuery that matches entities with the Unlock component; the job is scheduled over this query.

  • private bool m_SkipUpdate = true
    Flag used to skip the system's first update after creation or after PreDeserialize. The system sets this true to avoid acting immediately and provides SkipUpdate() to set it again.

  • private TypeHandle __TypeHandle
    Internal container holding ComponentTypeHandle / ComponentLookup instances used by the HighlightJob. Populated via __AssignHandles in the TypeHandle struct when the system is initialized.

Properties

  • (No public properties)
    This system exposes no public properties. It communicates via its public methods (PreDeserialize, SkipUpdate) and via ECS components.

Constructors

  • public UIHighlightSystem()
    Default parameterless constructor. The system relies on ECS lifecycle methods (OnCreate, OnUpdate, etc.) for initialization and operation.

Methods

  • protected override void OnCreate()
    Initializes the system: obtains/creates an EndFrameBarrier, builds the query for unlocked prefabs (ComponentType.ReadOnly()), and calls RequireForUpdate on that query so the system runs only when matching entities exist.

  • protected override void OnUpdate()
    Main update: if m_SkipUpdate is true the system clears the flag and returns (skips this update). Otherwise it constructs a HighlightJob, fills its handles and a command buffer from m_EndFrameBarrier, schedules the job over m_UnlockedPrefabQuery (JobChunk), stores the returned JobHandle in base.Dependency, and registers that handle with the EndFrameBarrier via AddJobHandleForProducer so the command buffer playback is synchronized.

  • public void PreDeserialize(Context context)
    IPreDeserialize implementation. Removes any existing UIHighlight components from all entities (creates an EntityQuery for UIHighlight and removes the component), disposes the query, and sets m_SkipUpdate = true to avoid immediate processing right after deserialization.

  • public void SkipUpdate()
    Sets m_SkipUpdate = true so the next frame the system will skip its work. Can be used by external code to prevent the system from executing on the immediate next update.

  • private void __AssignQueries(ref SystemState state)
    Compiler-generated helper to build/assign any EntityQuery instances used by the system. The generated version in this class currently just creates and disposes an empty EntityQueryBuilder; the important query (m_UnlockedPrefabQuery) is created in OnCreate.

  • protected override void OnCreateForCompiler()
    Compiler helper called by codegen; calls __AssignQueries and __TypeHandle.__AssignHandles to populate internal handles/queries at system initialization time.

Nested types and job methods (summary)

  • private struct HighlightJob : IJobChunk
    Job executed over chunks matching Unlock. It holds:
  • read-only ComponentTypeHandle m_UnlockType
  • read-only ComponentLookup m_ObjectDatas
  • read-only ComponentLookup m_AssetCategories
  • read-only ComponentLookup m_ToolbarGroups
  • EntityCommandBuffer m_CommandBuffer

Execute(in ArchetypeChunk chunk, ...) iterates Unlock components in the chunk. For each Unlock: - tries to get the UIObjectData for unlock.m_Prefab (the prefab entity) - if found, retrieves the group entity (componentData.m_Group) - if that group has a UIAssetCategoryData, the job adds UIHighlight to: unlock.m_Prefab, the group entity, and the category's menu (componentData2.m_Menu) - else if the group has UIToolbarGroupData, the job adds UIHighlight only to unlock.m_Prefab The job uses the EntityCommandBuffer to add components (safe to run in a job).

  • private struct TypeHandle
    Holds the read-only ComponentTypeHandle/ComponentLookup fields used by the job and provides __AssignHandles(ref SystemState state) which fetches those handles/lookups from the provided SystemState. This is called during system initialization (OnCreateForCompiler).

Usage Example

// Example usage from mod code to get the system and optionally skip its next update:
using Unity.Entities;
using Game.UI.InGame;

// Obtain the system (World depends on context; in many mods use DefaultWorld)
var world = World.DefaultGameObjectInjectionWorld;
var uiHighlightSystem = world.GetOrCreateSystemManaged<Game.UI.InGame.UIHighlightSystem>();

// Prevent the system from running on the next update
uiHighlightSystem.SkipUpdate();

// Typical behavior: to make an item get highlighted in the UI, add an Unlock component to
// a prefab entity (structure of Unlock depends on game's code). The system will pick up
// entities with Unlock and add UIHighlight to the prefab and related UI entities at end frame.

Notes and tips for modders: - The system relies on the Unlock component being present on prefab entities. To trigger highlighting, add or create an Unlock component on the target prefab entity via EntityManager.AddComponentData. - UIHighlight components are added via an EndFrameBarrier command buffer; they will be applied after the scheduled job completes and the barrier plays back. - PreDeserialize removes UIHighlight components before scene/context deserialization to avoid stale highlight state after load. If your mod needs to preserve highlights across save/load, you must re-apply them after deserialization.