Game.Prefabs.Modes.FireMode
Assembly:
Game (Assembly-CSharp typical for mods)
Namespace:
Game.Prefabs.Modes
Type:
class
Base:
LocalModePrefab
Summary:
FireMode is a LocalMode prefab component used to configure and apply runtime Fire-related data (FireData) for event prefabs. It exposes an array of ModeData entries (each pointing to an EventPrefab and a set of fire parameters) and provides methods to record referenced component changes, apply the configured mode values to entity components, and restore entities to their prefab default fire values. This is intended for use in Cities: Skylines 2 modding to control how fire events behave per-mode (start probability/intensity, spread probability/range).
Fields
-
public ModeData[] m_ModeDatas
An array of ModeData entries. Each ModeData links an EventPrefab that contains a Fire component and the fire parameters to apply for this mode. -
public class ModeData
Serializable nested class used to store per-prefab fire parameters. -
public EventPrefab m_Prefab
Reference to an EventPrefab which is expected to contain a Fire component. -
public float m_StartProbability
Start probability to apply to the prefab's FireData.m_StartProbability. -
public float m_StartIntensity
Start intensity to apply to the prefab's FireData.m_StartIntensity. -
public float m_SpreadProbability
Spread probability to apply to the prefab's FireData.m_SpreadProbability. -
public float m_SpreadRange
Spread range to apply to the prefab's FireData.m_SpreadRange.
Notes:
- ModeData is marked [Serializable], so instances are typically configured in the prefab inspector.
- The code assumes the referenced EventPrefab’s GetComponent
Properties
This class does not declare any public C# properties.
Constructors
public FireMode()
Default constructor (implicit if not defined). Instances are normally created/instantiated by Unity as part of prefab loading.
Methods
public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
Iterates over m_ModeDatas and, for each entry:- Obtains the Fire component from the referenced EventPrefab.
- If missing, logs a critical error and continues.
- Gets the Entity associated with the component's prefab via prefabSystem.GetEntity(component.prefab).
- Calls entityManager.GetComponentData
(entity) — this effectively touches/records the component data so the system can track that this prefab/entity has FireData (used by prefab change/record workflows).
Notes: - This method does not change values; it is used to ensure the referenced FireData component is known to the EntityManager / PrefabSystem for change tracking.
public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
For each ModeData entry:- Finds the Fire component on the referenced EventPrefab. Logs and skips if missing.
- Resolves the Entity for the prefab.
- Reads the current FireData from the EntityManager.
- Overwrites FireData fields (m_StartProbability, m_StartIntensity, m_SpreadProbability, m_SpreadRange) using the values from the ModeData.
- Writes the updated FireData back with entityManager.SetComponentData(entity, componentData).
Notes: - Use this to apply the mode-specific fire settings to runtime entities so the event behaves according to the mode configuration.
public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
For each ModeData entry:- Gets the Fire component from the referenced EventPrefab. Logs and skips if missing.
- Resolves the Entity for the prefab.
- Reads the current FireData from the EntityManager.
- Restores FireData fields from the values present on the Fire component itself (these are the prefab defaults).
- Writes the restored FireData back to the entity.
Notes: - This restores runtime-modified FireData back to the prefab defaults defined on the Fire component, useful when disabling a mode or resetting changes.
Behavioral and modding notes: - Missing Fire component on the referenced EventPrefab triggers ComponentBase.baseLog.Critical($"Target not found {this}") and that entry is skipped; ensure EventPrefab references are correct. - The methods require a valid Unity.Entities.EntityManager and the game's PrefabSystem to resolve prefab entities. - These methods operate on ECS component data (FireData) — ensure the FireData struct layout matches expected fields. - Because operations occur per-entry, large arrays may cause runtime cost; consider batching or limiting entries when applying at runtime.
Usage Example
// Example: manually apply FireMode settings at runtime (usually called by the game's mode manager).
// Assume fireMode is a FireMode component reference (from a prefab), and entityManager/prefabSystem are available.
fireMode.ApplyModeData(entityManager, prefabSystem);
// To restore defaults later:
fireMode.RestoreDefaultData(entityManager, prefabSystem);
// During prefab change recording stage:
fireMode.RecordChanges(entityManager, prefabSystem);
Additional example: programmatically creating a ModeData entry
// Create and configure a ModeData entry in code (usually you'd set this up in the prefab inspector)
var modeData = new FireMode.ModeData {
m_Prefab = someEventPrefab,
m_StartProbability = 0.1f,
m_StartIntensity = 1.5f,
m_SpreadProbability = 0.05f,
m_SpreadRange = 10f
};
myFireMode.m_ModeDatas = new[] { modeData };