|
Post by Vineet on Apr 24, 2022 6:34:21 GMT
HI,
Currently I'm developing a Sandbox game which has lot of different items and each item is pooled and created at the start. Which increases the loading time and total pooled objects go upto 1500+.
So I was wondering how can I enable the Instantiate more with a max limit and after that objects start to recycle. This way I can set the preload quantity of all objects to 1 and have them instantiate to a limit and then they can recycle, which is very efficient.
How can I achieve this?
|
|
|
Post by DarkTonic Dev on Apr 24, 2022 16:17:33 GMT
Instantiate More does have an Item Limit field. Whether you've reached your limit or not, items that are inactive in the pool are used before attempting to Instantiate more. If you've reached your limit all are in the Scene active, no more can be spawned until some are despawned.
However, you should know that the goal of Pooling is to avoid slow performance. Instantiating during play may in fact slow down your game quite a bit. A simple loading screen with game tips gives the user something to read while the pool loads up. Not sure what kind of device or load time we're talking about here.
-Brian
|
|
|
Post by noobvulcan on Apr 26, 2022 6:43:12 GMT
Hi,
You are right as well that instantiating during play may slow down the game but it depends on how you use it (like instantiating bullets is not good at all).
Anyways I was able to implement the "Instantiate more with a max limit and then recycle" feature with a small change in the Spawn function, but it doesn't support editor scripting
// Instantiate a new one var curCount = NumberOfClones(itemSettings); if (curCount >= itemSettings.ItemHardLimit) {
itemSettings.AllowInstantiateMore = false; itemSettings.AllowRecycle = true; if (itemSettings.AllowRecycle) { cloneToSpawn = itemSettings.SpawnedClones[0]; // keep the SpawnedClones and DespawnedClones arrays in line. Despawn(cloneToSpawn); }
//Debug.LogWarning( // "The Transform '" + itemName + // "' has reached its item limit in Pool Boss. Please increase your Preload Qty or Item Limit."); //return null; }
So far it works perfectly fine. Do let me know if this will cause any issues which I'm not able to see at the moment.
How this is more performant in my case -
As it's a sandbox game so it has and will have lots of objects. Currently, the pooled objects counts go up to 1500+ and this will increase with each new item added. So pooling this many objects at the start takes up a lot of memory and also increases loading time. With this new feature "Instantiate more with a max limit and then recycle", only the required object will get instantiate to a limit, and then it will start recycling. Also, note that objects are not getting Destroyed.
Also, I think you should implement this feature as well as I saw a few more users wanted to implement this.
Thanks Vineet
|
|
|
Post by DarkTonic Dev on Apr 26, 2022 14:25:31 GMT
Hi, can you send me the entire PoolBoss.cs file and I'll see about adding this in and analyzing the impact. You can email us at support@darktonic.com
-B
|
|
|
Post by noobvulcan on Apr 27, 2022 4:44:14 GMT
Mailed you
|
|
|
Post by DarkTonic Dev on Apr 27, 2022 5:09:25 GMT
I'll take a look tomorrow, thanks!
|
|