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.
- Listed in World generation
- Inherits or implements
HashedGeneralValue<PopulationDefinition> - Derived types
PopulationDefinition,PopulationDefinition.Create - Nested types
Create,FestivePrefabGroup,PopulationImpact,RandomRotationType - Attributes
TypeConverter,HashedPath - Documented in Populations and spawners, Arguments and results
Constructors
| Member | What it is |
|---|---|
PopulationDefinition() | Use ScriptableObject.CreateInstance instead of new; Unity loads the saved ones from assets. |
Fields
21 private and internal fields
| Member | What it is |
|---|---|
private AttributeImpact[] attributes | Backing field for Attributes. The ecosystem multiplies these impacts by the biome attributes to size the population. |
private float disconnectRadius | Backing field for DisconnectRadius. Above 0, spawned entities get a radial population item, else a bounds one. |
private Distribution distribution | Optional distribution picked from by spawn attributes. When null, prefabHashes (or an active festive group) is used. |
private PopulationDefinition.FestivePrefabGroup[] festiveGroups | Prefab lists tied to festivities. The first active one replaces prefabHashes. |
private bool isAllowingDisconnect | Backing field for IsAllowingDisconnect. If set, spawned entities can leave the population by moving away. |
private bool isCreature | Backing field for IsCreature. Creatures save as creatures and join the chunk directly; others are children of the spawner. |
private bool isKinematicOnSpawn | Backing field for IsKinematicOnSpawn. Makes the spawned entity's rigidbody kinematic. |
private bool isUsingPointRotation | Backing field for IsUsingPointRotation. Spawned entities take the spawn point's rotation. |
private bool isUsingRandomRotation | Backing field for IsUsingRandomRotation. Adds a random rotation of randomRotationType on spawn. |
private bool isUsingSafeSpawning | Backing field for IsUsingSafeSpawning. Lifts the spawn by the entity's largest collider bounds size. |
private LayerMask layersToAvoid | Layers the sphere cast checks in IsPositionValid. |
private static readonly Logger logger | NLog logger for this class. |
private int maxPopulationGrowth | Backing field for MaxPopulationGrowth: most members added in one population tick. 5 by default. |
private float onDeathOccupyPointFor | Backing field for OnDeathOccupyPointFor: seconds a spawn point stays taken after its entity dies. |
private float percentageOfPopulationSpawned | Backing field for PercentageOfPopulationSpawned: share of the current population that exists as entities. |
private AnimationCurve populationGrowthCurve | Backing field for PopulationGrowthCurve: growth chance by fill fraction. Values over 1 can add several per tick. |
private Vector3 positionForSphereCast | Offset from the spawn point for the IsPositionValid sphere check. |
private uint[] prefabHashes | Network prefab hashes picked from at random when there is no distribution. |
private PopulationDefinition.RandomRotationType randomRotationType | Whether the random rotation is around Y only or any axis. |
private float sphereCastRadius | Radius of the IsPositionValid sphere check. 0 or less turns the check off. |
private float tickFrequency | Backing field for BaseTickFrequency: seconds between population checks, before overrides and the spawn rate multiplier. |
Properties
| Member | What 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
| Member | What 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:
SettingsCommandModules.PopulationSettings.CheckPopulationTime, SettingsCommandModules.PopulationSettings.ResetPopulationTime, SettingsCommandModules.PopulationSettings.SetPopulationTime, SpawnCommandModule.SpawnPopulation, CavePopulationSpawnInformation.GetRandom, Ecosystem.PopulationApplication.definition, Ecosystem.PopulationApplication.Definition, IPopulationFolderSaveDataBase.Definition, PointsPopulationValue.GetRandom, PopulationDefinition.PopulationImpact.affectingPopulation, PopulationDefinitionManager.GetValue, PopulationDefinitionManager.ResetValue, PopulationDefinitionManager.SetValue, PopulationDefinitionManager.ValuedUpdated, PopulationFolderBase.PopulationDefinition, PopulationFolderSaveData.definition, PopulationFolderSaveData.Definition, PopulationFolderSaveData1.definition, PopulationSample.CheckTimeUpdated, PopulationSample.Definition, PopulationSample.PopulationSample, PopulationSpawnArea.populationDefinition, PopulationSpawnArea.PopulationDefinition, PopulationSpawnArea.Setup, PopulationSpawnAreaSaveData.definition, PopulationSpawnAreaSaveData.Definition, PopulationSpawnAreaSaveData1.definition, PopulationSpawnInformation.GetRandom, SimplePopulationValue.GetRandom, SpawnAreaDisplay.targetPopulations, SpawnPointsDisplay.targetPopulation.