Skip to content

Game.Prefabs.GarbagePrefab

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: Class

Base: PrefabBase

Summary:
GarbagePrefab is a Prefab class used to configure global garbage system parameters and references for a garbage-related prefab entity in Cities: Skylines 2. At runtime it populates a GarbageParameterData component on the prefab entity with references to other prefabs (service & notification prefabs) and a set of numeric thresholds/balances that drive garbage production, collection requests, warnings, accumulation caps and happiness effects. This class is used by the game's prefab system (PrefabSystem) during LateInitialize to convert inspector-assigned PrefabBase references into entity references and write the parameter component used by the ECS systems that implement garbage simulation.


Fields

  • public ServicePrefab m_GarbageServicePrefab
    Reference to the ServicePrefab that handles garbage (e.g., collection/processing). During LateInitialize this is converted to an Entity and stored in GarbageParameterData.m_GarbageServicePrefab.

  • public NotificationIconPrefab m_GarbageNotificationPrefab
    Reference to the notification icon prefab used when garbage-related notifications are raised. Converted to an Entity in LateInitialize and stored in GarbageParameterData.m_GarbageNotificationPrefab.

  • public NotificationIconPrefab m_FacilityFullNotificationPrefab
    Reference to the notification icon prefab used when a garbage facility is full. Converted to an Entity and stored in GarbageParameterData.m_FacilityFullNotificationPrefab.

  • public int m_HomelessGarbageProduce = 25
    Amount of garbage produced by each homeless person. Used to calculate garbage production for homeless population.

  • public int m_CollectionGarbageLimit = 20
    Threshold amount used to decide when collection is requested/triggered for a building or area.

  • public int m_RequestGarbageLimit = 100
    Threshold used to request additional garbage service (e.g., request trucks or services).

  • public int m_WarningGarbageLimit = 500
    Threshold that triggers warnings (UI/notifications) when garbage accumulation is excessive.

  • public int m_MaxGarbageAccumulation = 2000
    Maximum amount of garbage that can accumulate for a single building/plot before being capped.

  • public float m_BuildingLevelBalance = 1.25f
    Multiplier that adjusts garbage production according to building level. Higher values increase production for higher-level buildings.

  • public float m_EducationBalance = 2.5f
    Multiplier affecting how education level modifies garbage production (e.g., more educated citizens may produce different amounts).

  • public int m_HappinessEffectBaseline = 100
    Baseline accumulated garbage amount at which happiness is affected. Used together with m_HappinessEffectStep to compute happiness penalties.

  • public int m_HappinessEffectStep = 65
    Step value added to baseline to determine the accumulated garbage thresholds that reduce happiness (e.g., baseline + step, baseline + 2*step, etc.).

Properties

  • public override bool ignoreUnlockDependencies { get; }
    Returns true in this prefab (override). Indicates that this prefab ignores unlock dependencies — it is available irrespective of unlock progression constraints used by the prefab unlocking system.

Constructors

  • public GarbagePrefab()
    Default parameterless constructor (implicit). No custom initialization beyond field defaults declared in the class.

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Adds this prefab's referenced prefabs (m_GarbageServicePrefab, m_GarbageNotificationPrefab, m_FacilityFullNotificationPrefab) to the provided dependency list. This ensures referenced prefabs are available/loaded before this prefab is used.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds ComponentType.ReadWrite() to the provided set. This instructs the prefab system to include the GarbageParameterData component on the prefab entity so ECS systems can read its configuration.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Overrides base method but does not add extra archetype components beyond what the base provides. It calls the base implementation.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Called after the prefab entity has been created. This method:

  • Gets the PrefabSystem instance for the world.
  • Converts inspector PrefabBase references (ServicePrefab and NotificationIconPrefab fields) into Entity references using PrefabSystem.GetEntity.
  • Fills a GarbageParameterData struct with those entity references and all numeric configuration values from this class (homeless production, limits, balances, happiness parameters).
  • Writes the GarbageParameterData into the prefab entity via entityManager.SetComponentData(entity, componentData). This is the key method that bridges editor-assigned prefab references and the runtime ECS data used by garbage systems.

Usage Example

Reading the configured GarbageParameterData for a prefab entity at runtime:

// Assume you have references to World, PrefabSystem and EntityManager
PrefabSystem prefabSystem = world.GetOrCreateSystemManaged<PrefabSystem>();
EntityManager entityManager = world.EntityManager;

// Convert the GarbagePrefab (PrefabBase) to its entity (the prefab entity)
Entity garbagePrefabEntity = prefabSystem.GetEntity(myGarbagePrefab);

// Read the populated GarbageParameterData written during LateInitialize
GarbageParameterData data = entityManager.GetComponentData<GarbageParameterData>(garbagePrefabEntity);

// Example: inspect the max accumulation
int maxAccumulation = data.m_MaxGarbageAccumulation;

Notes: - The prefab fields referencing other prefabs are converted to entity references in LateInitialize; when writing systems that consume GarbageParameterData, expect entity IDs for referenced prefabs. - Tweak numeric values here to balance garbage production, service request frequency, and the effect on citizen happiness.