I got a Pool script from the asset store (SmartPool) and you access each pool you have created via script, like this:
SmartPool.Spawn("Pool1");
But as I have lots of pools containing different things I am having to make a fresh script file for every single pool. I would love to be able to alter the name of the pool in the inspector so I dont need a load of scripts that all do the same thing, is this possible?
Sure… you can create a string variable and just declare it public. then set it in your property inspector.
// declaration section of your class/script...
public string poolName;
....
// wherever you call your pool...
SmartPool.Spawn(poolName); // you might want to check if the string is empty first
I use FastPool instead, which uses integers rather than strings for pool names (harder to remember, but typically a bit better to store), but basically I have a wrapper for my pooling calls that I call my PoolManager. I just make a call to it to spawn whatever it needs, passing the pool ID by a variable. The concept for SmartPool would be similar… there’s actually a demo project I found here too: Unity3d Smart Object Pooling · GitHub
Only thing is, that demo doesn’t use a variable for the pool name, it’s actually hard coded. But that’s a very simple switch (see my code above).
Unfortunately that is the method I tried to start with and it doesn’t work with SmartPool. Im not sure why, but the name of the pool is set up like a tag ((“Pool1”).
I might check out FastPool, but SmartPool was free and it does work well as a simple pool manager.
Oh I’m sure SmartPool is fine. I wasn’t suggesting you use something different. Just saying I wasn’t 100% familiar with SmartPool, but it should work similarly.