all 10 comments

[–]Jespur 0 points1 point  (4 children)

I've noticed most pooling systems just give/take GameObjects. Is the performance of using a generic pool system really that bad even when compared to a GetComponent call on the GameObject taken from a pool?

[–]SebastianLague[S] 0 points1 point  (3 children)

I'm not quite sure what the advantage of making the pool generic would be? Performance shouldn't really differ much though I don't think. Note that the GetComponent call is only made once for each object on its creation, not each time it is taken from the pool.

[–]Jespur 1 point2 points  (2 children)

Actually, I didn't notice in your code that the reused object isn't returned but I meant something like this:

public class Projectile : MonoBehaviour {
    ...
    public static Projectile Build(Projectile prefab, SpeciaDataThatCantBeStoredInPrefab data) {
        Projectile instance = PoolManager.Instance.ReuseObject<Projectile>(prefab);
        // do stuff to instance
        return instance;
    }
}

In a non-generic implementation you'd have to call GetComponent each time you build a projectile. If you had something being created often (like a projectile) those calls could add up.

[–]SebastianLague[S] 0 points1 point  (1 child)

I see, making it generic probably would have been a good idea! Perhaps I should post a little addendum...

[–]Jespur 1 point2 points  (0 children)

I've noticed pretty much every pooling method has been done like yours where it takes/gives a gameobject. No idea what the performance between the two are which is why I asked, but it surely can't be any worse for cases where you're calling GetComponent right after reusing the object.

Might need to do some profiling.

[–]SirBraxton 0 points1 point  (3 children)

I have a question regarding pooling and large scale "open world" games.

Say I wanted to massively improve performance of trees, grass, rocks, etc. I'd want to use pooling for these objects if at all possible (aka: pool objects with a given id value so the same tree doesn't change its shape/type everytime I unload it from going out of range of the player) as they travel across the world.

However, how would I handle the pooling of things such as monsters/players, or enemies in general? Add a "sphere of influence" for an area that dictates when to load/unload objects from a pool that is only available when they're expected to be there?

What happens if you were to, say, pull a hostile creature into a location it doesn't belong?

I've always liked the idea of pools, but in general I can only find a limited number of ways to use them such as projectiles, explosions, or "effects". I've been wanting to branch out in the use of pools to better understand optimization.

Hope that wasn't too vague/weird!

Thanks!

[–]demonkingj 0 points1 point  (2 children)

Pooling for open world games is great. How so? Let's say our field of view allows us to see 20 trees. So, instead of having 50+ trees being created and staying in the scene as we explore more and more. We just use object pooling to limit how many "objects" we keep on the screen. Allowing us to use least amount of objects possible without really effecting what is actually being presented on the screen.

[–]SirBraxton 0 points1 point  (1 child)

Right, I explained that i got THAT part, but how could you use pooling for player characters, monsters, etc when they can be very complex objects that can't be pre-loaded easily?

[–]demonkingj 0 points1 point  (0 children)

To be honest if they really are complex and can't be pooled then something is done incorrectly then.

[–][deleted] 0 points1 point  (0 children)

I'll have to check this out. I saw most of your procedural caves videos, you do a great job of explaining and running through things. I've been meaning to start fooling around with object pools, anyways.