Object Pooling

The MLAPI has built-in support for Object Pooling. This is useful for frequently used objects such as bullets. This can be achieved by registering custom spawn and destroy handlers.

SpawnHandler

SpawnManager.RegisterCustomSpawnHandler(SpawnManager.GetPrefabHash("myPrefabName"), (position, rotation, disabled) =>
{
    // Called when the MLAPI want's to spawn a prefab with the name "myPrefabName"
});

DestroyHandler

SpawnManager.RegisterCustomDestroyHandler(SpawnManager.GetPrefabHash("myPrefabName"), (networkedObject) =>
{
    // Called when the MLAPI want's to destroy the given NetworkedObject
});