Skip to main content

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.

Constructors​

MemberWhat it is
PopulationSpawnArea()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

13 private and internal fields
MemberWhat it is
private bool arePointsStaticWhen on, picks numberOfSpawnPoints fixed points at start. When off, asks the spawn positions for a point each time.
private LocationChunk chunkUnused location chunk field.
private bool destroySpawnedWithThisDestroys everything the population spawned when this area is destroyed (not on unload).
private bool isOneOffSpawns once when the chunk loads, then destroys the area. Saved.
private bool isSpawnPointsInitializedWhether the static spawn points have been picked.
private static Logger loggerClass logger.
private int maxPopulationMost entities alive at once. Halved (rounded up) for creatures on simple servers. Saved.
private int numberOfSpawnPointsHow many static points to pick. Saved.
private PopulationSpawnInformation populationThe spawn information (points or simple) handed to the population.
private PopulationDefinition populationDefinitionBacking field for PopulationDefinition.
private List<SpawnPoint> spawnPointsThe static spawn points in use.
private MonoBehaviour spawnPositionsThe component that gives spawn positions (an ISpawnPositions).
private int startingPopulationHow many to spawn when the population starts. Saved.

Properties​

MemberWhat 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
MemberWhat it is
private PopulationSpawnInformation this[uint populationHash] { get; }Returns this area's spawn information for any hash.

Methods​

MemberWhat 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
MemberWhat 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.