Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
24 lines (20 sloc) 705 Bytes
title permalink
Object Pooling
/wiki/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
});
You can’t perform that action at this time.