Skip to main content

SpawnedElement

A class in Root.Township, Alta.Populations.

Server: one slot of a global population in a location chunk. It picks a spot, spawns the prefab when the chunk is fully loaded, and can decay after a set time.

Constructors​

MemberWhat it is
SpawnedElement(LocationChunk locationChunk, NetworkPrefab prefab, GlobalPopulationDefinition populationDefinition, float decayTime)Creates a SpawnedElement from locationChunk, prefab, populationDefinition and decayTime.

Fields​

9 private and internal fields
MemberWhat it is
private Timeline.IEntry decayTimeline entry for the decay timer, or null when there is none.
private NetworkEntity entityBacking field for Entity.
private bool hasDecayedSet when the decay timer ended while the entity was alive.
private bool hasRaycastedWhether the spawn position and rotation were already picked. They're reused on later respawns.
private LocationChunk locationChunkBacking field for LocationChunk.
private GlobalPopulationDefinition populationDefinitionThe global population definition that owns this slot.
private Vector3 positionPicked spawn position.
private NetworkPrefab prefabPrefab spawned for this slot.
private Quaternion rotationPicked spawn rotation: random yaw, aligned to the ground normal unless on A*.

Properties​

MemberWhat it is
NetworkEntity Entity { get; }The spawned entity, or null when it isn't spawned (chunk not loaded, or it was destroyed).
LocationChunk LocationChunk { get; }The location chunk this slot belongs to.

Methods​

MemberWhat it is
void Initialize()Spawns now if the chunk is fully loaded, and again each time it fully loads.
4 private and internal methods
MemberWhat it is
private void Decay()Runs when the decay timer ends. Removes the slot now if nothing is spawned, else marks it to go when the entity next unloads or dies.
private void Destroy()Cancels the decay timer, removes the slot from its population definition and unhooks from the chunk.
private void EntityDestroyed(NetworkEntity entity, bool isUnload)When the entity goes, ends the slot unless it was only a chunk unload of an undecayed slot. Clears entity either way.
private void SpawnElement(Chunk chunk)Finds a spot the first time (raycast, or nearest A* node), then spawns the prefab there with save mode set to ignore.

Used in​

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