ChunkDestroyer Abstract Class

public abstract class ChunkDestroyer : MonoBehaviour

Provides a base implementation for Chunk Destroyers.

Chunk Destroyers can be used to customize the destruction strategy used by the Stremable Assets Manager. Basically, whenever an object needs to be destroyed, rather than calling GameObject.Destroy on the object (the default behaviour when no Chunk Destroyer is present), the chunk will be passed off to the Chunk Destroyer.

This allows you to create custom destruction solutions that fit your particular child-parent hiearchy.

For instance, you can create a destroyer that destroys all grandchildren in one frame, then all those grandchildren's parents in the next frame, and finally the root game object in the last frame.

The Destroyer must be supplied in the "Chunk Destroyer" option in the inspector of whatever ChunkManager Component you are using.

Methods

DestroyChunk(GameObject, ChunkStreamer.ChunkStreamerUser)

public abstract IEnumerator<YieldInstruction> DestroyChunk(GameObject chunk, ChunkStreamer.ChunkStreamerUser ChunkStreamerUser)

When overridden by a derived class, can be used to destroy a single chunk (game object) in a more performant manner than simply using GameObject.Destroy.

Parameters

Name Type Description
chunk GameObject

The chunk (game object) that needs to be destroyed.

ChunkStreamerUser ChunkStreamer.ChunkStreamerUser

The user which triggered the method call. Typically you will not need the data from this user, however it is provided in case you do. If you are using the Chunk Destroyer with a custom Chunk Streamer that utilizes a custom ChunkStreamerUser derived class, you can cast this user object to the type you know it is.

Returns

IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine. See the YieldInstruction page for more info.


DestroyChunksOnCells(List<WorldCell>, MemoryFreeingStrategy, ChunkStreamer.ChunkStreamerUser)

public abstract IEnumerator<YieldInstruction> DestroyChunksOnCells(List<WorldCell> cells, MemoryFreeingStrategy memoryFreeingStrategy, ChunkStreamer.ChunkStreamerUser ChunkStreamerUser)

When overridden by a derived class and assigned to a Chunk Manager, can be used to customize the behaviour for how chunks (game objects/chunks) are removed from the active scene.

Note that in most instances all chunks will be present, however if your game removes chunks manually (i.e., outside of the scope of SAM), you should take this into account and check to make sure the chunks are not null before trying to destroy them.

Parameters

Name Type Description
cells List<WorldCell>

The cells with the chunks needing to be destroyed/unloaded. You must use the DetachChunksFromCell to get each chunk from each cell, which is only available when the WorldCell is casted to a IDetachableWorldCell. This method both retrieves the chunk and nulls out the cells reference to it. Since World Chunks are reused internally by SAM, this latter point is very important. Failing to call DetachChunksFromCell for all chunks on all cells will certainly result in unexpected behaviour.

memoryFreeingStrategy MemoryFreeingStrategy

The Memory Freeing Strategy set in the inspector of the calling Chunk Manager. You can make use of this value or ignore it.

ChunkStreamerUser ChunkStreamer.ChunkStreamerUser

The user which triggered the method call. Typically you will not need the data from this user, however it is provided in case you do. If you are using the Chunk Destroyer with a custom Chunk Streamer that utilizes a custom ChunkStreamerUser derived class, you can cast this user object to the type you know it is.

Returns

IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine. See the YieldInstruction page for more info.