DistancePoolingChunkManager Class

public sealed class DistancePoolingChunkManager : PoolingChunkManager

Provides an implementation for a Chunk Manager that deactivates chunks when they are not in use until the cells those objects belong to are a specified distance from the active cell the player is in (at which time they are destroyed).

Note, the operation that checks for obsolete objects is run on a coroutine separate from the World, therefore it will not respect the World's Execution Controller.

This component is usable with both Game Objects and non Game Object Chunks, however there are certain methods of the Chunk Manager class that are by default configured to work with Game Objects. Those methods include:

GetChunkPosition - For retrieving the Vector3Double position of a chunk. Only called if the LOD using this manager has 'Chunks Use Positional Data' enabled (this setting can be found on your Streamable Grid asset).

SetChunkPosition - For setting the chunk position to a Vector3Double value. Only called if the LOD using this manager has 'Chunks Use Positional Data' enabled (this setting can be found on your Streamable Grid asset).

SetChunkActiveState - For setting the state of the chunk to active or deactive. This method is called only if Auto Activate/Deactivate Cell Chunks is enabled in your World inspector, for any LODs that use this manager.

If you anticipate any of these methods being called, you will need to create a custom class deriving from this one, and in that class override the methods that will be called, so that they function correctly with your custom chunks.

Methods

AwakeExtended()

protected sealed override void AwakeExtended()

Used to perform some initialization.


CreateNewUser(ILODGroup, int)

protected sealed override ChunkManagerUser CreateNewUser(ILODGroup lodGroup, int chunkStreamerUserID)

Creates a new DistanceBasedPoolingChunkManagerUser, which is a custom type which derives from ChunkManagerUser. This user object contains an object pool used specifically by this class.

Parameters

Name Type Description
lodGroup ILODGroup

The lod group being registered.

chunkStreamerUserID int

When the LODGroup registered with the manager, the manager automatically registered the LODGroup with the Chunk Streamer associated with it. This is the user ID assigned to the LODGroup by that Chunk Streamer.

Returns

ChunkManagerUser
A new user object created using the worldAssociatedWithUser as input.


OnUserDeRegistered(ChunkManagerUser)

protected sealed override void OnUserDeRegistered(ChunkManagerUser user)

Unsubscribes the user from On Cell Player Is In Changed events.

Parameters

Name Type Description
user ChunkManagerUser

The user that was just de-registered


ProcessDeactivatedCell(WorldCell, PoolingChunkManagerUser)

public sealed override void ProcessDeactivatedCell(WorldCell cell, PoolingChunkManagerUser userCellBelongsTo)

Checks the distance of the cell from the cell the player is in. If the distance is greater than that defined in the inspector, the cells chunks will not be added to the pool. If it is within distance, they will be added if there is room in the pool. The cell will also be added to a list of cells which are distance checked whenever the cell the player is in changes. If the cell ever becomes too far from the cell the player is in, it will be removed from this list and the pool that stores chunks associated with that cell will be emptied if needed. Note that multiple endless grid cells can make use of the same chunks if they use the same Streamable Grid Cell. In these cases, a pool may not be emptied, as there may be other cells still within distance that might need them in the future.

Parameters

Name Type Description
cell WorldCell

The cell which needs to be processed.

userCellBelongsTo PoolingChunkManagerUser

The user this cell belongs to.