Skip to main content

ChunkDetector

A class in Root.Township, the global namespace.

Server: keeps a chunked entity in the right chunk by re-evaluating its chunk whenever its transform moves. Only runs while the entity has no parent chunker and isn't in the global chunk.

Constructors​

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

Fields​

MemberWhat it is
static uint TestingStatic counter not used anywhere in the game code.
6 private and internal fields
MemberWhat it is
private Chunker chunkerThe entity's Chunker.
private static UpdateModule chunkUpdateModuleShared update module that runs every detector's check during Update.
private bool isEnabledBacking field for IsEnabled.
private static Logger loggerNLog logger for this class.
private Transform targetTransformTransform watched for movement. Set to this transform by default.
private IUnityUpdateMethod updateHandle of the registered per-frame check, or null.

Properties​

MemberWhat it is
bool HasUpdate { get; }True while the per-frame chunk check is registered.
bool IsEnabled { get; set; }Turns detection on or off. Can only be on for the server.

Methods​

MemberWhat it is
override void InitializeAsServer(SpawnData spawnData)Schedules DelayInitialize for the next frame.
7 private and internal methods
MemberWhat it is
private void CheckForChunkUpdate()Per-frame update: re-evaluates the chunk if the target transform has changed. Logs and rethrows if the entity is gone.
private void DelayInitialize()One frame after server init, enables the component if the entity is still alive and has a real identifier.
private bool EditorSetup()Editor helper: sets the target transform to this one and disables the component by default.
private void OnDisable()Removes the update and the parent-change hook.
private void OnEnable()Gets the entity's chunker, starts checking if it has no parent, and watches for parent changes.
private void RegisterUpdate()Evaluates the chunk once, then registers the per-frame check (skipped for global-chunk entities).
private void StartCheckingForChunkChange(Chunker oldChunkerParent, Chunker newChunkerParent)Stops checking when the chunker gets a parent (the parent decides the chunk) and resumes when it's unparented.

Used in​

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