Skip to main content

PopulationDefinition

A class in Root.Township, Alta.Populations.

An asset describing one kind of population (creatures, plants, ore and so on): which prefabs to spawn, how fast it grows and how spawns are placed. Used by population samples on the server.

Constructors​

MemberWhat it is
PopulationDefinition()Use ScriptableObject.CreateInstance instead of new; Unity loads the saved ones from assets.

Fields​

21 private and internal fields
MemberWhat it is
private AttributeImpact[] attributesBacking field for Attributes. The ecosystem multiplies these impacts by the biome attributes to size the population.
private float disconnectRadiusBacking field for DisconnectRadius. Above 0, spawned entities get a radial population item, else a bounds one.
private Distribution distributionOptional distribution picked from by spawn attributes. When null, prefabHashes (or an active festive group) is used.
private PopulationDefinition.FestivePrefabGroup[] festiveGroupsPrefab lists tied to festivities. The first active one replaces prefabHashes.
private bool isAllowingDisconnectBacking field for IsAllowingDisconnect. If set, spawned entities can leave the population by moving away.
private bool isCreatureBacking field for IsCreature. Creatures save as creatures and join the chunk directly; others are children of the spawner.
private bool isKinematicOnSpawnBacking field for IsKinematicOnSpawn. Makes the spawned entity's rigidbody kinematic.
private bool isUsingPointRotationBacking field for IsUsingPointRotation. Spawned entities take the spawn point's rotation.
private bool isUsingRandomRotationBacking field for IsUsingRandomRotation. Adds a random rotation of randomRotationType on spawn.
private bool isUsingSafeSpawningBacking field for IsUsingSafeSpawning. Lifts the spawn by the entity's largest collider bounds size.
private LayerMask layersToAvoidLayers the sphere cast checks in IsPositionValid.
private static readonly Logger loggerNLog logger for this class.
private int maxPopulationGrowthBacking field for MaxPopulationGrowth: most members added in one population tick. 5 by default.
private float onDeathOccupyPointForBacking field for OnDeathOccupyPointFor: seconds a spawn point stays taken after its entity dies.
private float percentageOfPopulationSpawnedBacking field for PercentageOfPopulationSpawned: share of the current population that exists as entities.
private AnimationCurve populationGrowthCurveBacking field for PopulationGrowthCurve: growth chance by fill fraction. Values over 1 can add several per tick.
private Vector3 positionForSphereCastOffset from the spawn point for the IsPositionValid sphere check.
private uint[] prefabHashesNetwork prefab hashes picked from at random when there is no distribution.
private PopulationDefinition.RandomRotationType randomRotationTypeWhether the random rotation is around Y only or any axis.
private float sphereCastRadiusRadius of the IsPositionValid sphere check. 0 or less turns the check off.
private float tickFrequencyBacking field for BaseTickFrequency: seconds between population checks, before overrides and the spawn rate multiplier.

Properties​

MemberWhat it is
AttributeImpact[] Attributes { get; }Biome attribute impacts that scale the population for the area's biome.
float BaseTickFrequency { get; }Seconds between population ticks as set on the asset (default 5).
float DisconnectRadius { get; }When disconnecting is allowed, how far a member can move from the spawner before leaving the population. 0 uses bounds instead.
bool IsAllowingDisconnect { get; }Whether members leave the population (and stop counting) when they move far away.
bool IsCreature { get; }Whether members are creatures. Creatures save as creatures and are skipped on simple servers.
bool IsKinematicOnSpawn { get; }Makes the spawned rigidbody kinematic.
bool IsUsingPointRotation { get; }Whether spawns use the spawn point's rotation.
bool IsUsingRandomRotation { get; }Whether a random rotation is added to spawns.
bool IsUsingSafeSpawning { get; }Raises spawns by their largest collider size so they don't start inside the ground.
int MaxPopulationGrowth { get; }Most members the population can grow by in one tick.
float OnDeathOccupyPointFor { get; }Seconds a spawn point stays occupied after its member dies.
float PercentageOfPopulationSpawned { get; }Fraction of the current population that is actually spawned as entities.
AnimationCurve PopulationGrowthCurve { get; }Chance of growing per tick, by current population as a fraction of max. Values above 1 can add several at once.
float TickFrequency { get; }Seconds between ticks: the current (possibly overridden) value divided by the server's spawn rate multiplier.

Methods​

MemberWhat it is
uint GetRandom(SpawnData spawnData)Picks a prefab hash to spawn, from the distribution if set, otherwise from the prefab list (or an active festive group's list).
Quaternion GetRandomRotation()A random rotation around Y only, or fully random, depending on the asset.
bool IsPositionValid(SpawnPoint point)False when a sphere check at the spawn point hits the avoided layers. Always true if the sphere radius is 0 or less.
PopulationSample Load(PopulationFolderBase parent, IPopulationFolderSaveDataBase data)Creates a population sample from saved data.
void Save(PopulationSample sample, IPopulationFolderSaveDataBase data)Writes a sample's current and max population and check time to save data.
PopulationSample Serialize(PopulationSample baseSample, Stream stream, PopulationFolderBase parent)Obsolete stream format for population samples.

Used in​

Members of other types that take, return or hold a PopulationDefinition: