Skip to content

Game.Tools.SelectedUpdateSystem

Assembly: Assembly-CSharp
Namespace: Game.Tools

Type: class

Base: GameSystemBase

Summary:
System that keeps the tool selection (ToolSystem.selected) pointing to a valid, live entity. On each update it checks the current selection stored in ToolSystem and, if the selected entity is missing or marked Deleted, attempts to resolve a replacement by: - following an Owner component from an Icon back to its owner entity, - resolving a Resident to its m_Citizen entity, - resolving a Pet to its m_HouseholdPet entity. If no valid replacement is found the selection is cleared (set to Entity.Null). The class is marked with [CompilerGenerated] (likely decompiler artifact) and its methods/constructor are annotated with [Preserve] to avoid stripping.


Fields

  • private ToolSystem m_ToolSystem
    Holds a reference to the global ToolSystem. This is initialized in OnCreate via World.GetOrCreateSystemManaged() and is used to read and update the current selection (m_ToolSystem.selected).

Properties

  • None. This system accesses selection through the ToolSystem instance rather than exposing its own properties.

Constructors

  • public SelectedUpdateSystem()
    Default parameterless constructor. Marked with [Preserve] in the original source to prevent code stripping. No other construction-time initialization is performed.

Methods

  • protected override void OnCreate() : System.Void
    Initializes m_ToolSystem by retrieving/creating the ToolSystem managed system from the ECS World:
  • Calls base.OnCreate().
  • Calls World.GetOrCreateSystemManaged() and stores the result in m_ToolSystem. Notes: This method is annotated with [Preserve] in the original code.

  • protected override void OnUpdate() : System.Void
    Per-frame update that validates and potentially corrects ToolSystem.selected:

  • If m_ToolSystem.selected == Entity.Null, returns early.
  • If the EntityManager reports the selected entity does not exist, clears selection (Entity.Null).
  • Otherwise, if the selected entity is marked with the Deleted component, tries to find a replacement:
    • If the entity has an Icon component and an Owner component whose m_Owner entity exists and is not Deleted, selection is set to that owner.
    • If the (possibly owner) entity has a Resident component whose m_Citizen exists, selection is set to m_Citizen.
    • Else if the entity has a Pet component whose m_HouseholdPet exists, selection is set to m_HouseholdPet.
  • After attempting resolution, if the resulting selection is still marked Deleted, selection is cleared (Entity.Null). Notes:
  • Uses EntityManager.Exists, HasComponent, TryGetComponent / TryGetComponent(out T) to inspect entities and components.
  • Components referenced: Deleted, Icon, Owner, Resident, Pet and their fields (Owner.m_Owner, Resident.m_Citizen, Pet.m_HouseholdPet).
  • The method is annotated with [Preserve] in the original code.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Cache the ToolSystem so this system can read/write the current selection.
    m_ToolSystem = World.GetOrCreateSystemManaged<ToolSystem>();
}

Additional notes for modders: - This is a managed ECS system intended to run inside the game's World. Do not attempt to instantiate it manually; let the World create/manage systems or register it if adding a custom world/system set. - If you need to intercept or change selection behavior, modify ToolSystem.selected (or override/replace ToolSystem) rather than patching this system directly, unless you intentionally want to change the resolution logic above. - Be careful when creating or deleting entities that are referenced by Owner/Resident/Pet components to keep selection consistent. - The [Preserve] attributes indicate the methods/constructor should survive linking/stripping; when building mods, ensure your build/setup respects Preserve where required.