Skip to content

Instantly share code, notes, and snippets.

@peroon
Created November 26, 2015 11:58
Show Gist options
  • Save peroon/2f4837faba50a6e32b13 to your computer and use it in GitHub Desktop.
Save peroon/2f4837faba50a6e32b13 to your computer and use it in GitHub Desktop.
Object Pooling
// Object pool.
Queue<GameObject> objectPool;
objectPool = new Queue<GameObject>();
..
// Reuse the oldest object in the pool.
var go = objectPool.Dequeue();
go.SetActive(false);
go.transform.position = position;
if (rotationMode != RotationMode.Keep)
go.transform.rotation = rotation;
go.SetActive(true);
objectPool.Enqueue(go);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment