Skip to content

Game.Prefabs.CrimeAccumulation

Assembly:
Assembly-CSharp.dll

Namespace:
Game.Prefabs

Type:
class

Base:
ComponentBase

Summary:
A prefab component used by service/zone prefabs to provide crime accumulation configuration to an entity. This component exposes a configurable m_CrimeRate (default 7f) which is written into the DOTS component CrimeAccumulationData during prefab initialization. Use this to control the baseline crime accumulation rate applied to the prefab's entity in Cities: Skylines 2 modding.


Fields

  • public float m_CrimeRate
    Default: 7f. The crime rate value assigned to the entity's CrimeAccumulationData during Initialize. Adjust this value on the prefab to change how quickly crime accumulates for that service/zone.

Properties

  • None

Constructors

  • public CrimeAccumulation()
    Implicit default constructor. The class relies on ComponentBase lifecycle overrides rather than custom construction logic.

Methods

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    This override is present but empty — the component does not add any components to archetypes at this stage.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds CrimeAccumulationData as a ReadWrite component type to the prefab's component list: components.Add(ComponentType.ReadWrite());

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called during prefab initialization. Creates a CrimeAccumulationData instance, sets its m_CrimeRate from this prefab's m_CrimeRate, and writes it to the entity via EntityManager.SetComponentData(entity, componentData).

Notes: - CrimeAccumulationData is expected to be an IComponentData struct defined elsewhere. This component simply seeds that DOTS component with the configured value. - This code runs at prefab initialization time; ensure you perform EntityManager operations only where safe within the game's initialization flow.

Usage Example

// Example: the component's Initialize implementation (already in the prefab)
public override void Initialize(EntityManager entityManager, Entity entity)
{
    base.Initialize(entityManager, entity);
    CrimeAccumulationData componentData = default;
    componentData.m_CrimeRate = m_CrimeRate; // m_CrimeRate configurable on the prefab
    entityManager.SetComponentData(entity, componentData);
}

Additional tips for modders: - To change crime behavior, either modify m_CrimeRate on the prefab asset or create a derived prefab that sets a different value. - If you need more complex initialization (e.g., per-instance randomization or dependency on other prefab values), override Initialize and ensure you still add the required component types in GetPrefabComponents. - Ensure you reference the correct assembly and DOTS types when working with EntityManager and IComponentData in Cities: Skylines 2 mods.