PopulationSpawnArea
A class in Root.Township, Alta.Populations.
Server: a placed spawner that keeps a population of one definition alive at fixed or generated spawn points, with a starting and maximum count. Also acts as its own spawn system.
- Listed in World generation
- Inherits or implements
PopulationFolder<PopulationSpawnArea, PopulationSpawnAreaSaveData>,ISpawnSystem - Derived types
PopulationSpawnArea,PopulationSpawnAreaSaveData - Documented in Populations and spawners
Constructors
| Member | What it is |
|---|---|
PopulationSpawnArea() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
13 private and internal fields
| Member | What it is |
|---|---|
private bool arePointsStatic | When on, picks numberOfSpawnPoints fixed points at start. When off, asks the spawn positions for a point each time. |
private LocationChunk chunk | Unused location chunk field. |
private bool destroySpawnedWithThis | Destroys everything the population spawned when this area is destroyed (not on unload). |
private bool isOneOff | Spawns once when the chunk loads, then destroys the area. Saved. |
private bool isSpawnPointsInitialized | Whether the static spawn points have been picked. |
private static Logger logger | Class logger. |
private int maxPopulation | Most entities alive at once. Halved (rounded up) for creatures on simple servers. Saved. |
private int numberOfSpawnPoints | How many static points to pick. Saved. |
private PopulationSpawnInformation population | The spawn information (points or simple) handed to the population. |
private PopulationDefinition populationDefinition | Backing field for PopulationDefinition. |
private List<SpawnPoint> spawnPoints | The static spawn points in use. |
private MonoBehaviour spawnPositions | The component that gives spawn positions (an ISpawnPositions). |
private int startingPopulation | How many to spawn when the population starts. Saved. |
Properties
| Member | What it is |
|---|---|
static bool IsSkippingCreatures { get; set; } | Static. When true, spawn areas for creature populations destroy themselves on start. |
override PopulationDefinition PopulationDefinition { get; protected set; } | What this area spawns, set in the inspector or with Setup. |
protected override bool AddToEcosystem { get; } | False: spawn areas don't join the chunk's ecosystem. |
1 private and internal property
| Member | What it is |
|---|---|
private PopulationSpawnInformation this[uint populationHash] { get; } | Returns this area's spawn information for any hash. |
Methods
| Member | What it is |
|---|---|
void DestroyPopulation(bool isUnload) | Server: destroys the population. Also destroys its spawned entities if set to, unless the area is only unloading. |
void ForceDestroy() | Kills everything the population spawned, then destroys the population. |
void ForceMax() | Spawns up to the population's maximum straight away. |
void ForceSpawn(int targetPopulation) | Spawns up to the given count straight away. |
override void InitializeAsServer(SpawnData spawnData) | Builds spawn points and the population (halving creature counts on simple servers), then checks spawns once its chunk is loaded. |
void Preview() | Editor: draws 5000 sample spawn positions as red lines for 10 seconds. |
void Setup(PopulationDefinition populationDefinition, int startingPopulation, int maxPopulation) | Server: sets the definition, starting population and maximum. Call before the area initializes. |
protected override void LoadSetup(PopulationSpawnAreaSaveData data) | Restores spawn point count, starting and max population and the one-off flag from save data. |
protected override void SaveSetup(PopulationSpawnAreaSaveData data) | Writes spawn point count, starting and max population and the one-off flag to save data. |
protected override void SerializeSetup(Stream stream) | Reads or writes the same setup values on a stream. |
5 private and internal methods
| Member | What it is |
|---|---|
private void CheckSpawned(Chunk chunk) | When the chunk is fully loaded, runs the population check a couple of frames later. One off areas then destroy themselves. |
private void DestroySample(NetworkEntity entity, bool isUnload) | Destroys the population when the entity is destroyed. |
private void InitializeChunk(Chunk newChunk) | Initializes the population for its chunk if needed and checks spawns once the chunk is fully loaded. |
private void OnDrawGizmosSelected() | Draws the static spawn points as small blue spheres. |
private void RemoveFromChunk(Chunk chunk) | Stops listening to the old chunk's FullyLoaded. |