Game.Prefabs.CreatureSpawner
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
Component used on scene prefabs to define creature-spawning behaviour for Cities: Skylines 2. When the prefab is converted into ECS entities, this Component ensures the prefab has the required prefab ECS components (PlaceholderObjectElement and CreatureSpawnData) and the runtime archetype includes Game.Creatures.CreatureSpawner and OwnedCreature components. It transfers the inspector-set m_MaxGroupCount value into the CreatureSpawnData component on the entity during initialization.
Fields
public int m_MaxGroupCount = 3
Maximum number of creatures to spawn in a single group. Default value is 3. During Initialize, this value is copied into the CreatureSpawnData component on the entity.
Properties
- None
Constructors
public CreatureSpawner()
No explicit constructor is defined in the class; the default parameterless constructor is used. Initialization of ECS component data is handled in Initialize(EntityManager, Entity).
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds components required on the prefab entity:- ComponentType.ReadWrite
() -
ComponentType.ReadWrite
()
These ensure the prefab will carry data required for creature spawning when converted to ECS. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds runtime archetype components that should exist on instantiated entities: - ComponentType.ReadWrite
() -
ComponentType.ReadWrite
()
These components are part of the runtime simulation for creatures. -
public override void Initialize(EntityManager entityManager, Entity entity)
Called during prefab-to-entity initialization. Copies the inspector field m_MaxGroupCount into a new CreatureSpawnData struct and writes it to the entity via entityManager.SetComponentData(entity, componentData). Also calls base.Initialize(entityManager, entity).
Usage Example
// Typical usage: attach CreatureSpawner to a prefab GameObject in the editor,
// set m_MaxGroupCount in the inspector. At prefab conversion time the engine
// will call Initialize and the value will be stored in the entity's
// CreatureSpawnData component.
public class ExamplePrefabSetup
{
void ConfigureSpawner(GameObject prefab)
{
var spawner = prefab.GetComponent<Game.Prefabs.CreatureSpawner>();
if (spawner == null)
spawner = prefab.AddComponent<Game.Prefabs.CreatureSpawner>();
// Configure max creatures per group before conversion
spawner.m_MaxGroupCount = 5;
}
}
Notes: - The class depends on the CreatureSpawnData, PlaceholderObjectElement, Game.Creatures.CreatureSpawner, and OwnedCreature ECS component types; those must be defined elsewhere in the mod/game codebase. - This class is focused on transferring simple configuration (m_MaxGroupCount) from the MonoBehaviour prefab into the ECS world during initialization.