Search Unity

Object Pooling

Discussion in 'Scripting' started by iNoMore, Aug 20, 2014.

  1. iNoMore

    iNoMore

    Joined:
    Oct 13, 2013
    Posts:
    64
    Hi
    A quick question about the concept of object pooling
    As I understand its the use of lets say a list of inactive game object, that when you need them you enable them, and when they die, you disable them and get them back in the list

    I understand its useful to avoid the overhead of spawning an object, and calling the GC on Destroy call
    and also have all the Start function happen at the loading sequence and not while playing

    Does that technique apply to a really big number of of objects?
    Lets say an RTS, where you can have 300 of the same unit instance, should I still use object pooling? create 300 units on Start screen and keep then inactive when not needed? (keep in mind that its 300 for each unit type?)

    Or should I just create a safe number of lets say, 50, and then when more are needed spawn them but if they die keep them in the list?

    I am trying to wrap my head around the concept usage

    Also, do you know any other "techniques" that are used for similar things?
    I am trying to understand the general rules of thumb when it comes to optimizations and resources usage

    Thanks a lot :)
     
  2. Glockenbeat

    Glockenbeat

    Joined:
    Apr 24, 2012
    Posts:
    670
    I'd go for the "spawn x of that type and keep references" approach. You don't even need to pre-spawn said amount, the important part is to not destroy the objects.

    I personally like the Pool Manager by Path-o-Logical which does a pretty good and straight forward job and enables you to go for any of the options you mentioned.

    http://poolmanager.path-o-logical.com/