Skip to main content

LocationChunk

A class in Root.Township, Alta.Chunks.

A Chunk that is a place in the world, with bounds, neighbours, an environment and static scene content. Overworld tiles, caves and forest chunks are location chunks. Both sides; on clients ChunkWithLocalPlayer is the one you are standing in.

Constructors​

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

Fields​

MemberWhat it is
ChunkEffect[] chunkEffectsEffects applied on clients when the local player enters or leaves the chunk.
static Action<LocationChunk> OnChunkWithLocalPlayerChangedStatic callback run when the local player moves to another location chunk (null when cleared).
21 private and internal fields
MemberWhat it is
private static HashSet<LocationChunk> allLocationChunksStatic set behind AllLocationChunks; chunks add themselves on Initialize and remove themselves on destroy.
private List<string> androidNormalPointerContent pointers loaded instead of normalPointer on Android.
private Bounds boundsBacking field for Bounds, the area the chunk covers.
private Bounds bufferBoundsBounds grown by BufferSize; backing field for BufferBounds.
private Vector3 bufferBoundsMaxTop corner of bufferBounds; the upper limit when positions are serialized for this chunk.
private Vector3 bufferBoundsMinBottom corner of bufferBounds; the lower limit when positions are serialized for this chunk.
private const float BufferSizeHow much (10 units) BufferBounds is larger than Bounds in total size.
private ChunkRegion chunkRegionWhich region the chunk belongs to (overworld by default); can be changed with SetLocationDestination.
private List<string> colliderOnlyPointerContent pointers loaded on a headless server instead of the normal ones, probably the collider-only version of the static content.
private ChunkConnections connectionsBacking field for Connections: the chunk's links to its neighbours.
private BasicEcosystem ecosystemThe BasicEcosystem on the same object, passed to the environment in Initialize.
private ChunkEnvironment environmentBacking field for Environment; also supplies the chunk's SpawnData.
private static bool hasSetLocationChunksSet once GetLocationChunksInPlayMode has filled its cache.
private bool isOverridingSafePositionWhen set, the chunk the local player is in changes how the player's safe position is tracked; read through the static IsOverridingSafePosition.
private bool isSkippingStaticContentBacking field for IsSkippingStaticContent.
private bool isUsingCustomLoadDistanceWhen set, loadDistance replaces the streaming settings' load radius for this chunk.
private float loadDistanceCustom load radius (default 3) used when isUsingCustomLoadDistance is set.
private static readonly Logger loggerNLog logger for this class.
private List<string> normalPointerContent pointers for the chunk's static content on non-Android clients.
private ChunkPositions positionsBacking field for Positions; chunks with surfaces are also added to ContentLocationChunks.
private int priorityBacking field for Priority; when chunks overlap, the chunk lookup picks the one with the highest priority.

Properties​

MemberWhat it is
static HashSet<LocationChunk> AllLocationChunks { get; }Static set of every location chunk that has initialised.
Bounds Bounds { get; set; }The chunk's world space bounds. Setting it also updates BufferBounds.
Bounds BufferBounds { get; }Bounds grown by 10 units in size. Positions in this chunk are sent quantised to these bounds.
virtual ChunkRegion ChunkRegion { get; }Which region the chunk belongs to (overworld by default).
static LocationChunk ChunkWithLocalPlayer { get; private set; }Client: static, the location chunk the local player is currently in.
List<string> ColliderOnlyPointer { get; }Static content to load on a headless server: colliders only, no visuals.
ChunkConnections Connections { get; }Adjacent chunks and connection costs, used to decide which neighbours load around a player.
static HashSet<LocationChunk> ContentLocationChunks { get; }Static set of location chunks with spawn surfaces, used when picking a random chunk to spawn things in.
float DynamicLoadStrength { get; }Load budget for dynamic content around this chunk: its custom load distance or the streaming default, times the dynamic multiplier.
ChunkEnvironment Environment { get; }The chunk's environment settings, which also supply its SpawnData.
bool HasLocalPlayer { get; private set; }Client: true while the local player is inside this chunk.
static bool IsOverridingSafePosition { get; }Static, true when the local player's chunk has the override safe position flag. Then fall-recovery safe positions come from safe position setters instead of normal movement.
static bool IsRecheckingChunks { get; set; }Editor only: whether AllLocationChunks searches the scene again each time in edit mode.
override bool IsSkippingStaticContent { get; }Set on the prefab. When true the server skips this chunk's static content.
List<string> NormalPointer { get; }Static content to load on clients. A separate list is used on Android.
ChunkMatrix OffsetMatrix { get; set; }Transform from the prefab's original placement to where this chunk actually sits. Set by placed cave chunks and applied by the dynamic content manager.
IPortalApplier PortalApplier { get; set; }Cave portal handler that toggles terrain visibility for this chunk, if it is part of a cave.
ChunkPositions Positions { get; }Spawn surface definitions used to pick random spawn points in the chunk.
int Priority { get; }When several chunks contain a point, the one with the highest priority wins.
override SpawnData SpawnData { get; }Spawn data from the chunk's environment, so spawned content knows its biome.
float StaticLoadStrength { get; }Load budget for static content: custom load distance or the streaming default, times the static multiplier.

Events​

MemberWhat it is
event Action<bool> HasLocalPlayerChangedRaised when the local player enters or leaves this chunk. Chunk effects hook it on clients.

Methods​

MemberWhat it is
static void ClearChunkWithLocalPlayer()Client: clears ChunkWithLocalPlayer and tells that chunk the player left.
virtual void GetNeighboursForLoading(float remainingLoadBudget, HashSet<Chunk> result)Adds the neighbours that fit in the remaining load budget (minus each connection's cost) to the result set.
virtual IEnumerable<LocationChunk> GetNeighboursForLookup()The forced adjacent chunks, used when searching nearby chunks.
void GetOverrideLoadDistance(out bool isUsingCustomLoadDistance, out float overrideLoadingDistance)Reads whether a custom load distance is used and its value.
override void Initialize()Sets up environment and connections, hooks chunk effects on clients and adds itself to the static sets.
void OnLocalPlayerChange(bool isContained)Client: updates HasLocalPlayer and ChunkWithLocalPlayer, and raises the change events.
virtual void PlayerEnteredChunk(Player player)Hook run when a player moves into this chunk. Empty here; cave layer chunks override it.
override void SerializePosition(Stream stream, ref Vector3 position, NetworkEntity entity = null)Sends a position quantised to BufferBounds at 1 mm precision, so it must lie inside them.
void SetLocationDestination(ChunkRegion newDestination)Changes the chunk's ChunkRegion.
void SetOverrideLoadDistance(float overrideLoadingDistance, bool isOverriding = true)Turns on a custom load distance for this chunk with the given value. The second argument is ignored.
protected override void OnDestroy()Removes the chunk from the static sets.
2 private and internal methods
MemberWhat it is
private static HashSet<LocationChunk> GetLocationChunksInEditMode()Editor only: refills allLocationChunks with every LocationChunk in the scene when IsRecheckingChunks is set.
private static HashSet<LocationChunk> GetLocationChunksInPlayMode()Editor play mode: finds every LocationChunk once and caches the set.

Used in​

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

CaveLayerManager.entranceChunk, CaveLayerChunk.GetNeighboursForLookup, CaveLayerStaticObject.TryGetCaveLayerStreamer, CaveLayerStreamer.chunk, CaveLayerStreamer.Chunk, CaveLayerStreamer.RegisterPortal, ChunkAdjacencyConfiguration.chunk, ChunkAdjacencyConfiguration.Chunk, ChunkAdjacencyConfiguration.ChunkAdjacencyConfiguration, ChunkConnections.AddAdjacent, ChunkConnections.Chunk, ChunkConnections.ConnectTwoWay, ChunkConnections.Initialize, ChunkEnvironment.Initialize, FastChunkLookup.DeregisterOtherChunk, FastChunkLookup.FastChunkLookup, FastChunkLookup.GetAllChunksByIndex, FastChunkLookup.GetAllChunksContainingPosition, FastChunkLookup.GetAllChunksIntersectingBounds, FastChunkLookup.GetBestChunk, FastChunkLookup.GetBestChunkContainingPosition, FastChunkLookup.GetBestChunkIntersectingBounds, FastChunkLookup.otherChunks, FastChunkLookup.RegisterOtherChunk, FastChunkLookup.RemoveOtherChunk, ICaveLayer.Chunk, ICaveLayer.RegisterPortal, LocationChunkHelper.DeregisterOtherChunk, LocationChunkHelper.GetAllContaining, LocationChunkHelper.GetBestContaining, LocationChunkHelper.GetChunksToLoad, LocationChunkHelper.GetChunkWeightingsForPosition, LocationChunkHelper.GetRandomChunkForPosition, LocationChunkHelper.RegisterOtherChunk, LocationChunkHelper.RemoveOtherChunk, LocationChunkHelper.SetupChunkLookup, StaticCaveChunk.chunk, StaticCaveChunk.Chunk, StaticCaveChunk.RegisterPortal, AtmosphereManager.EnsureAtmosphere, BorderDefinedAtmosphere.allChunks, CliffFill.GenerateInternal, CutoutPathEdgeFill.GenerateInternal, ForestBridges.ClearDynamic, ForestBridges.ClearStatic, ForestBridges.GenerateDynamic, ForestBridges.GenerateStatic, ForestEncounters.ClearDynamic, ForestEncounters.ClearStatic, ForestEncounters.GenerateDynamic, ForestEncounters.GenerateStatic, ForestFill.GenerateInternal, ForestFillCore.ClearDynamic, ForestFillCore.ClearStatic, ForestFillCore.GenerateDynamic, ForestFillCore.GenerateInternal, ForestFillCore.GenerateStatic, ForestGeneration.chunkEdges, ForestGeneration.chunkNodes, ForestGeneration.GetEdgesWithinChunk and 84 more.