Object Pooling in Unity
August 24, 2019
Object Pooling
Unity
Youtube - Unity3D Object Pooling - How to use them & why you shouldBy: Unity3d College
This tutorial just seemed like a really useful concept so I wanted to make sure to note it down. Destroying lots of objects in Unity can lead to a lot of garbage collection, so you can use this concept of object pooling to help minimize this or remove it significantly.
The example used has a lot of objects that are spawning and then being destroyed. This can lead to lots of garbage collection because the newly unused memory needs to be accounted for in some way at some point. Object pooling helps get around this by not destroying the objects. You simply deactivate them, and then add them into a pool of deactivated objects. When you need to spawn another one, you just grab one of these deactivated objects and reactivate them instead.
It's a very useful concept that is pretty easy to implement. It will have the most impact when you are creating and destroying a decently high amount of objects, so keep an eye out for that as a time to use this methodology.
Comments
Post a Comment