#Any opinions on creating small object
1 messages · Page 1 of 1 (latest)
I wouldn't use a pool per tower. I would use a pool per projectile type.
Many towers of the same type can reuse the same pool
you could make a ProjectileManager object which maintains a Dictionary<ProjectileType, Pool> which the towers draw projectiles from.
The problem with one per tower is that you don't get nearly as much object reuse
you'll end up with overall higher memory usage, more objects in total, etc..
In fact typically I'd expect that most towers in a tower defense game don't actually have more than one active projectile at a time.
memory cost of populating the pool is spread out throughout game play time
This is true of a big pool as well. There seems to be a misconception that you need to preallocate the maximum number of objects you will need for an object pool, and this is simply not the case. A good object pool implementation only allocates objects on-demand.
Yes and I'm not seeing:
- can tune just enough projectiles to handle most cases
and - prefab is self contained
As good enough pros to outweigh the fact that you don't get good object reuse
which is the main benefit of an object pool in the first place.
Objects that in pool should be considered “destroyed” and shouldn’t really #have context, so global pool would make more sense.
Unless you want the pool to be destroyed when there is no tower that using the type of projectile, maybe?
Also having pool per tower is not “smaller”, it would be actually bigger in total
right but there's also the thing where if you have two towers that are firing ad different cadences, they can probably reuse a single projectile object when there's a global pool, which is not the case when there's a pool per tower
Do you have a lot of towers that actually have mutliple active projectiles at once?
I'd just write the global "pool manager" to dynamically create a pool for a given type (a particular prefab reference perhaps) on demand. No memorization required.
See LeanPool impelentation?
Kinda? I'm suggesting you to look into how other object pool system resolves issue you are wondering, so you can improve your system
You can use it for both global and local scenario
Not really, I'm suggesting to read actual code so you can get more practical ideas about object pooling. Object pooling is performance trick, it does not generally require much of abstraction over it.
I do think you are tend to question a lot of theoretical things that already known or discussed in CS, which is not a bad thing, but it needs to be practical at last.