Skip to main content

Cluster

A class in Root.Township, the global namespace.

A network entity that groups child entities (its parts) and destroys itself on the server once every part is gone. On server spawn it collects the network prefabs under its transform.

Constructors​

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

Fields​

MemberWhat it is
protected HashSet<NetworkEntity> partsThe entities currently in the cluster.

Methods​

MemberWhat it is
void Add(NetworkEntity part, bool isSingle, SpawnData spawnData)Adds an entity as a part and watches for it being destroyed. Pass isSingle true to call AddingFinished straight after.
virtual void AddingFinished(SpawnData spawnData)Hook for subclasses, called once the parts have been added. Does nothing by default.
virtual void CheckDestroy()Server: destroys the cluster entity if it has no parts left.
override void InitializeAsServer(SpawnData spawnData)Adds every child network prefab as a part, makes the cluster their chunking parent, then calls AddingFinished.
void Remove(NetworkEntity part)Removes a part, calls RemoveInternal, then CheckDestroy. Also runs when a part is destroyed.
protected virtual void AddInternal(NetworkEntity part)Hook for subclasses, called when a new part is added.
protected virtual void RemoveInternal(NetworkEntity part)Hook for subclasses, called when a part is removed.
1 private and internal method
MemberWhat it is
private void Remove(NetworkEntity part, bool isUnloading)Removes a part, calls RemoveInternal, then CheckDestroy. Also runs when a part is destroyed.

Used in​

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