Skip to main content

Chunker

A class in Root.Township, the global namespace.

Tracks which chunk a network entity is in, its chunking parent and children, and which players it is spawned for. Every NetworkEntity has one; you usually use the entity's own chunk members instead.

Constructors​

MemberWhat it is
Chunker(NetworkEntity networkEntity)Creates a Chunker from networkEntity.

Fields​

6 private and internal fields
MemberWhat it is
private readonly HashSet<Chunker> childrenChunkers parented to this one. They follow this chunker into whatever chunk it moves to.
private readonly IChunkedEntity chunkedEntityThe entity as IChunkedEntity, told when its parent changes.
private readonly HashSet<Player> despawningForPlayers whose despawn is waiting on a chunk move; finished in SetChunkInternal.
private static readonly Logger loggerNLog logger for this class.
private Chunker parentBacking field for Parent.
private readonly HashSet<Player> spawningForPlayers whose spawn is waiting on a chunk move; finished in SetChunkInternal.

Properties​

MemberWhat it is
int ChildCount { get; }Number of chunking children.
IEnumerable<Chunker> Children { get; }Chunkers that follow this one's chunk.
Chunk Chunk { get; private set; }The chunk the entity is in, or null.
bool IsServerOnly { get; private set; }Whether the entity is kept off clients.
NetworkEntity NetworkEntity { get; }The entity this chunker belongs to.
Chunker Parent { get; private set; }The chunking parent; children always take the parent's chunk.
HashSet<Player> SpawnedForPlayers { get; }Players the entity is currently spawned for.

Events​

MemberWhat it is
event ChunkEventHandler EnteredChunkRaised when the entity enters a chunk.
event ChunkEventHandler LeftChunkRaised when the entity leaves a chunk.
event ChunkerChangedHandler ParentChangedRaised with the old and new parent when it changes.

Methods​

MemberWhat it is
void EditorEvaluateChunk(FastChunkLookup chunkLookup)Editor: puts a root prefab entity into the chunk containing its position.
void EvaluateChunk()Server: moves a root entity to the chunk holding its position. Still chunkless on the next check, it is unloaded (player-held pickups go to their postbox).
void EvaluateChunk(bool isLoggingOnFailure)Server: moves a root entity to the chunk holding its position. Still chunkless on the next check, it is unloaded (player-held pickups go to their postbox).
void SetChunk(Chunk newChunk)Moves the entity (and its children) to a chunk. On the server this is ignored for entities with a chunking parent.
void SetParent(Chunker target, bool isDestroying = false)Sets the chunking parent (null to clear) and moves to its chunk.
void SetServerOnly(bool isServerOnly)Hides the entity from every player, or spawns it for the players in its chunk again.
6 private and internal methods
MemberWhat it is
private void IChunker.EndDespawn(Player target, bool isUnloading, bool isChunkSync)Explicit IChunker method: sends the entity destroyed message to the player for prefab entities.
private void IChunker.EndSpawn(Player target, bool isChunkSync)Explicit IChunker method: sends the initial serialization for serialized entities and runs OnConnected for the player.
private async void PostToPlayer(LocationChunk oldChunk, Vector3 position, int playerId)Pushes the entity into the postbox of the player who last held it, used when it falls out of every chunk.
private void SetChunkInternal(Chunk newChunk)Moves the entity and its child chunkers to a chunk, finishes pending spawns and despawns, and fires EnteredChunk and LeftChunk.
private bool IChunker.StartDespawn(Player target, bool hasMovedChunks, bool isChunkSync)Explicit IChunker method: removes the player from SpawnedForPlayers and runs OnDisconnected on the entity.
private bool IChunker.StartSpawn(Player target, bool hasMovedChunks, bool isChunkSync)Explicit IChunker method: adds the player to SpawnedForPlayers and sends the spawn message for prefab entities.

Used in​

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