Skip to content

Game.EconomyDebugSystem

Assembly: Assembly-CSharp
Namespace: Game.Debug

Type: class

Base: BaseDebugSystem

Summary:
EconomyDebugSystem is a debug-only ECS system used by Cities: Skylines 2 to visualize and inspect economic state for agents (households, companies, storage, etc.). It collects economic data via an IJobChunk (EconomyGizmoJob) and uses GizmosSystem to draw wireframe cubes over buildings that represent values such as company worth, stored resources, production, untaxed income, trade costs and household needs. The system registers several togglable debug options (Residential worth, Commercial worth, Industrial worth, Untaxed income, Storage used, Household need, Company Profitability, Trade Cost, Commercial storage) that control what the gizmos show. It also exposes several static helper/debugging methods for ad-hoc debugging (RemoveExtraCompanies, PrintTradeDebug, PrintAgeDebug, PrintSchoolDebug, PrintCompanyDebug).
{{ This system is intended for modding/debugging; it expects to run in the game's ECS world and depends on ResourceSystem and GizmosSystem. The heavy work is done in the nested EconomyGizmoJob which queries component buffers, transforms and resource prefabs to compute and render the debug gizmos. }}


Fields

  • private EntityQuery m_AgentQuery
    {{ Query selecting agent-like entities that have Game.Economy.Resources, PrefabRef and PropertyRenter and at least one of Household, ServiceAvailable, ProcessingCompany, StorageCompany or Profitability. Used as the primary query to schedule the EconomyGizmoJob. }}

  • private EntityQuery m_EconomyParameterQuery
    {{ Query used to fetch the singleton EconomyParameterData required by EconomyUtils and production/trade calculations. }}

  • private GizmosSystem m_GizmosSystem
    {{ Reference to the GizmosSystem used to obtain a GizmosBatcher for drawing the debug wire cubes. }}

  • private ResourceSystem m_ResourceSystem
    {{ Reference to the ResourceSystem used to get resource prefabs and to register read access for jobs. }}

  • private Option m_ResidentialOption
    {{ Option toggle for displaying residential household worth gizmos. }}

  • private Option m_CommercialOption
    {{ Option toggle for displaying commercial worth/service-related gizmos. }}

  • private Option m_CommercialStorageOption
    {{ Option toggle for highlighting commercial storage (materials) above a threshold. }}

  • private Option m_IndustrialOption
    {{ Option toggle for displaying industrial worth and input/output amounts. }}

  • private Option m_UntaxedIncomeOption
    {{ Option toggle for showing untaxed income values (TaxPayer.m_UntaxedIncome). }}

  • private Option m_StorageUsedOption
    {{ Option toggle for showing storage company used amounts and limits (colored by resource). }}

  • private Option m_HouseholdNeedOption
    {{ Option toggle for showing household need (HouseholdNeed.m_Amount). }}

  • private Option m_ProfitabilityOption
    {{ Option toggle for showing company profitability values. }}

  • private Option m_TradeCostOption
    {{ Option toggle for showing trade cost buy/sell bars for companies (draws separate colors for buy/sell and highlights expensive costs). }}

  • private TypeHandle __TypeHandle
    {{ Internal struct instance holding Entity/Component/Buffer/Lookup handles used to set up job access. Initialized in OnCreateForCompiler via __AssignHandles. }}

  • private struct EconomyGizmoJob (nested)
    {{ IJobChunk implementation that performs the per-chunk work: reads entity buffers/components (resources, trade costs, prefab refs, transforms, storage/company/process data, vehicles/owned vehicles, layout elements, etc.), computes values (company worth, stored resources, market prices, production, trade costs, profitability, household wealth/need) and issues draw calls through GizmoBatcher.DrawWireCube for each building/property. Contains helper Draw overloads to position and color the gizmo cubes. Scheduled in OnUpdate when the appropriate options/queries are present. }}

  • private struct TypeHandle (nested)
    {{ Container for all the ComponentTypeHandle/BufferTypeHandle/ComponentLookup/BufferLookup used by EconomyGizmoJob. Provides __AssignHandles(ref SystemState state) to initialize handles. }}


Properties

  • None (no public properties exposed).
    {{ All state is stored in private fields and the system exposes debug helpers as static methods. The debugging toggles are internal Option objects added via AddOption in OnCreate and displayed by the base debug UI. }}

Constructors

  • public EconomyDebugSystem()
    {{ Default constructor. Marked with [Preserve] via the generated attribute in the source; normal Unity ECS system instantiation applies. Initialization is performed in OnCreate. }}

Methods

  • protected override void OnCreate() : System.Void
    {{ Initializes references to GizmosSystem and ResourceSystem, constructs two queries (m_AgentQuery and m_EconomyParameterQuery), disables the system by default (base.Enabled = false), registers RequireForUpdate for the created queries and adds the debug options via AddOption. This is where the system's runtime dependencies and UI options are created. }}

  • protected override void OnUpdate() : System.Void
    {{ If the agent query is not empty, prepares an EconomyGizmoJob instance, fills it with all required handles/component lookups/prefabs/flags and schedules the job via JobChunkExtensions.ScheduleParallel. Adds the scheduled job handle to base.Dependency, registers the resource system as a reader of prefabs and the gizmo batcher write dependency. This method drives the per-frame debug rendering. }}

  • protected override void OnCreateForCompiler() : System.Void
    {{ Generated helper that calls __AssignQueries and __TypeHandle.__AssignHandles to wire up internal query and handle state for the compiler and runtime. }}

  • private void __AssignQueries(ref SystemState state) : System.Void
    {{ Generated placeholder present in the compiled file. In this decompiled source it creates a temporary EntityQueryBuilder and disposes it; query creation is actually performed in OnCreate. }}

  • public static void RemoveExtraCompanies() : System.Void
    {{ Static helper that marks all CompanyData entities which are not PropertyRenter (companies that are not attached to buildings/properties) as Deleted by adding the Deleted component to the entity query. Useful to quickly prune unattached companies in debugging scenarios. }}

  • public static void PrintTradeDebug(ITradeSystem tradeSystem, DynamicBuffer<CityModifier> cityEffects) : System.Void
    {{ Iterates all resources via ResourceIterator and logs import/export trade prices for Road/Air/Rail/Ship outside connection transfer types. Useful for inspecting the trade pricing returned by the provided ITradeSystem instance and the effect of city modifiers. }}

  • public static void PrintAgeDebug() : System.Void
    {{ Gathers households that are moving away and counts ages of citizens (based on TimeSystem day calculations) to produce an age histogram that is logged to Debug.Log. Uses household/citizen queries and the TimeData singleton. }}

  • public static void PrintSchoolDebug() : System.Void
    {{ Iterates Citizen entities to count children and log education levels; outputs basic statistics about processed children and how many are "ok" (educated above threshold). }}

  • public static void PrintCompanyDebug(ComponentLookup<ResourceData> resourceDatas) : System.Void
    {{ Inspects companies (service/industrial/workplace data), computes theoretical production per day using EconomyUtils and logs data about per-cell production, built pseudo trade costs and lists industrial input=>output mappings. Requires resourceDatas lookup and uses the ResourceSystem resource prefabs internally. Intended for detailed company/economy debugging. }}

  • void IJobChunk.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) (EconomyGizmoJob.Execute wrapper)
    {{ Explicit interface wrapper that forwards to the strongly-typed Execute method which contains the main logic for creating gizmo geometry per chunk. }}

  • private void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) (EconomyGizmoJob.Execute)
    {{ Core job logic: reads arrays and buffers from the chunk, checks which debug option is enabled and which components the chunk has (Household, ServiceAvailable, ProcessingCompany, StorageCompany, TaxPayer, Profitability, TradeCost, CargoTransportStation, etc.), computes values using EconomyUtils/GetMarketPrice/GetCompanyTotalWorth and draws appropriately positioned and colored cubes for visualization. Many branches handle different entity types (residential, commercial, industrial, storage) and different options (trade cost, profitability, commercial storage threshold). }}


Usage Example

// Enable the debug system (if present) so it will run its OnUpdate and draw gizmos:
var world = World.DefaultGameObjectInjectionWorld;
var econDebug = world?.GetExistingSystemManaged<Game.Debug.EconomyDebugSystem>();
if (econDebug != null)
{
    econDebug.Enabled = true;
}

// Call a static debug helper to remove stray companies:
Game.Debug.EconomyDebugSystem.RemoveExtraCompanies();

// Example: print trade prices using the ITradeSystem instance from the world
var tradeSys = world?.GetExistingSystemManaged<TradeSystem>() as ITradeSystem;
// cityEffects is a DynamicBuffer<CityModifier> from the appropriate entity (not shown here)
DynamicBuffer<CityModifier> cityEffects = default;
Game.Debug.EconomyDebugSystem.PrintTradeDebug(tradeSys, cityEffects);

{{ Notes: Most of the functionality is only meaningful inside the game's runtime ECS world. The visual output (gizmos) depends on GizmosSystem and ResourceSystem being present and on the internal EconomyUtils methods. The debug options are created by AddOption in OnCreate and are shown/controlled from the debug UI provided by the base system. Use the static Print* helpers for quick textual dumps of economic data. }}