Skip to main content

BasicPopulationItem

A class in Root.Township, Alta.Populations.

Added to a spawned population entity (such as an animal) to tie it to its BasicPopulation. Moving ones follow chunk changes and switch population. Server side.

Constructors​

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

Fields​

3 private and internal fields
MemberWhat it is
private LocationChunk currentChunkThe location chunk the item was last seen in, used by CheckMoved to spot chunk changes.
private Transform transformCached transform of the entity.
private IUnityUpdateMethod updateHandle for the registered CheckMoved update, removed when the item is destroyed or unloaded.

Properties​

MemberWhat it is
PopulationSetup Definition { get; set; }The population setup it was spawned from.
NetworkEntity Entity { get; set; }The spawned network entity.
BasicPopulation Population { get; set; }The population that currently counts this item. Changes when a moving item enters another chunk's population, null if that chunk has none.

Events​

MemberWhat it is
event BasicPopulationItem.PopulationItemEventHandler RemovedRaised when the item is removed from its population.

Methods​

MemberWhat it is
static BasicPopulationItem Create(BasicPopulation population, NetworkEntity entity)Adds the component to an entity, links it to the population and, for moving populations, starts checking which chunk it is in.
void Remove()Raises Removed and destroys this component. Called when the entity is destroyed, but not when it is only unloaded.
void ReplaceWith(NetworkEntity replacement)Asks the population to replace this item with another entity.
4 private and internal methods
MemberWhat it is
private void CheckMoved()Runs on a shared update module for moving items. When the item enters a new chunk it swaps population, or unloads if that chunk isn't loaded.
private void DestroyedByScene(NetworkEntity entity, bool isUnload)Handler for the entity's DestroyedByScene: stops movement checks and calls Remove unless it's just an unload.
private Chunk GetPositionChunk(NetworkEntity entity)Given to the entity as its chunk lookup: finds the location chunk that best contains the item's position.
private void ListenForMovement()Registers CheckMoved with the distance-check update module. Called from Create for populations marked as moving.

Used in​

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