Give Page Feedback | API

Chunk Managers - Custom Pooling Managers

If you want to create a Pooling Chunk Manager, one option is to derive directly from the PoolingChunkManager class, which provides a framework for performing pooling so that you don't have to implement as many members from the base ChunkManager class.

You can also use this to provide pruning logic, which is logic used to remove Asset Chunk Sets from the pools based on specific criteria.

In order to create a custom Pooling Chunk Manager, create a new MonoBehaviour script that derives from the PoolingChunkManager base class. This class provides default pooling logic and a single virtual method which can be overridden in order to slightly change the pooling logic.

You should place your class inside of the DeepSpaceLabs.SAM namespace, which will make the PoolingChunkManager class available and also help avoid naming conflicts with 3rd party assets or your own code.

--Special Note--
An easy way to start with your custom class is to hover over your custom class name and choose the option Show potential fixes -> Implement abstract class. This will provide default overrides for all abstract class members.

In addition, we recommend adding the following attribute above your class, which will ensure the custom chunk manager is shown with other Chunk Managers in menus:

[AddComponentMenu(GlobalValues.COMPONENT_ROOT_PATH + "Chunk Managers/Custom Pooling Chunk Manager Name")]

Drawbacks

There are two drawbacks to deriving from the Pooling Chunk Manager:

1) The Chunk Reuse Judge assigned to the Chunk Manager is never used for pooling logic.

2) Pooling is done on a per Streamable Grid Cell (per LOD Group user) basis and there is a maximum number of Asset Chunk Sets that can be stored for every Streamable Grid Cell.

If either of these drawbacks are deal breakers, you should derive from the ChunkManager base abstract class instead.

ShouldAddChunkSetToPool (Method - Implementation Optional)

You can override this method to provide alternative logic for deciding whether a World Cell's Asset Chunk Set should be added to the pool. Do note that the method is only queried when the pool has room for the Asset Chunks.

For example, you might only want the Chunk Set added when the World Cell is within a certain distance to the Player.

You can also use the method to perform secondary logic or add tracking information for the chunk sets, since they are guaranteed to be added to the pool when you return true (which you will know).

Pruning Logic

You can add pruning logic to your custom Pooling Chunk Manager to remove Asset Chunk Sets from the internal pools. The Distance Based Pooling Manager does this to remove Chunks belonging to World Cells that are too far from the current Cell the Player is in.

Pruning logic is best performed in a coroutine set to run once every X seconds. You will need to start this coroutine yourself, and stop it whenever the Chunk Manager script is disabled.

PoolManipulationInProgress

If performing pruning logic or any other action that adds or removes Asset Chunks from the pool, it's important to take the PoolManipulationInProgress property into account, which tracks whether another operation is in progress that adds and/or removes Asset Chunk Sets to/from the pool.

First, any time you wish to add/remove Asset Chunks, you must query this property and ensure it returns false before proceeding with the add/remove operations. Once it returns false, you must set it to true so that no other operation can perform add/remove operations at the same time.

Once you complete all add/remove operations, you can set it to false, which allows other operations to proceed.

This strategy is necessary to ensure that the state of the pools is always accurate. Because it is necessary to wait on this Property returning a certain value, it is recommended to place pool manipulation logic (such as pruning) in a coroutine. While you could also perform the logic in Update, it is much harder to script waiting logic.