Search Unity

[Released] Pool Boss - super easy pooling solution.

Discussion in 'Assets and Asset Store' started by jerotas, Oct 20, 2014.

  1. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    I have done this already for the Core GameKit implementation of PoolBoss for the next version (well not the stack but removed the random part and added a method to get the next item). Are you using Core GameKit or Pool Boss standalone?
     
  2. Shadeless

    Shadeless

    Joined:
    Jul 22, 2013
    Posts:
    136
    @jerotas
    I'm using Pool Boss standalone =/ Will it be added?
     
  3. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Yes, but it's such a small change that it won't be very soon. That doesn't warrant a release. I can send you a changed version if you email me.
     
  4. Shadeless

    Shadeless

    Joined:
    Jul 22, 2013
    Posts:
    136
    @jerotas
    That would be great, can you PM me your email?
     
  5. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
  6. Shadeless

    Shadeless

    Joined:
    Jul 22, 2013
    Posts:
    136
    @jerotas
    Hey I got the latest update and it seems to work great.

    I have another suggestion. It would be great if we had the option to do a delayed Spawn and Despawn built into Pool Boss. Sort of how Master Audio also has the option to specify a delay.

    It would be nice if it was built into Pool Boss, so we wouldn't have to use Coroutines or Invoke, or manual delays.

    What do you think about this?

    Cheers! :)
     
  7. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Sure, I'll put it on the roadmap. As always, it will make it into the Core GameKit version first.
     
  8. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    V 1.1 changelog:
    • Moved all classes into a namespace. If you are using code to call the API, you will need to add "using DarkTonic.PoolBoss;" at the top of those classes you use it in.
    • Fixed the namespace on Playmaker Custom Actions. If you are using these, you will need to re-import the new package or it will not compile.
    • Added NextPoolItemToSpawn method which will give you the next available item in a pool.
    • Removed random pool item selection. Now it always uses the first available.
     
  9. Shadeless

    Shadeless

    Joined:
    Jul 22, 2013
    Posts:
    136
    @jerotas
    Hey, can you please expose Recycle Oldest even when Allow Instantiate more is checked?
    For example, lets say I don't want to preload anything and I allow the pool to fill itself dynamically to the Item Limit I set. I still need Recycle Oldest even then... so yeah if its no problem please expose it in the editor.

    Oh also if all the items are taken does NextPoolItemToSpawn return null?

    Cheers!
     
  10. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Last question, yes it will return null.

    I'll put the other item on the roadmap. Just exposing it in the Inspector won't make it work, it will require code changes as well.
     
    Shadeless likes this.
  11. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    99thmonkey likes this.
  12. puzzlekings

    puzzlekings

    Joined:
    Sep 6, 2012
    Posts:
    404
    Hey Brian

    I just upgraded to the latest PoolBoss and there seems to be a bug in

    public static bool PrefabIsInPool(Transform trans)

    which I think may be something to do with the new categories you set up.

    Now this seems to always return false, even though an item is in PoolBoss.

    Please can you check?

    cheers,

    Nalin
     
  13. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Code looks fine to me. What's the prefab name you are passing in? Does it have "(Clone X)" in the name? If so, that's the problem and is not the way it should be used.

    I could add a call to GetPrefabName first inside PrefabIsInPool if that's the problem. Let me know.
     
  14. puzzlekings

    puzzlekings

    Joined:
    Sep 6, 2012
    Posts:
    404
    Yes it has (CloneX) in the name.

    This seemed to work ok with the previous release?
     
  15. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    In that case, change the following method:
    Code (csharp):
    1.  
    2.   /// <summary>
    3.   /// Call this method determine if the item name you pass in is set up in Pool Boss.
    4.   /// </summary>
    5.   /// <param name="transName">Item name you want to know is in the Pool or not.</param>
    6.   /// <returns>Boolean value.</returns>
    7.   public static bool PrefabIsInPool(string transName) {
    8.   if (_isReady) {
    9.  return PoolItemsByName.ContainsKey(GetPrefabName(transName));
    10.   }
    11.  Debug.LogWarning(NotInitError);
    12.   return false;
    13.   }
    14.  
    Let me know if that fixes the issue for you.
     
  16. puzzlekings

    puzzlekings

    Joined:
    Sep 6, 2012
    Posts:
    404
    Thanks Brian

    Unfortunately GetPrefabName(transName) does not exist in the latest build.

    Nalin
     
  17. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    I pasted that from PoolBoss.cs, in my working copy, so I believe it is there. You can email support@darktonic.com with your Asset Store invoice PDF for the latest at any time by the way.
     
  18. puzzlekings

    puzzlekings

    Joined:
    Sep 6, 2012
    Posts:
    404
    Yeah I can't find GetPrefabName that takes a parameter of string at all, so I have sent you an email.
     
  19. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    You're right. Added that one and replied to your email.
     
  20. puzzlekings

    puzzlekings

    Joined:
    Sep 6, 2012
    Posts:
    404
    jerotas likes this.
  21. nazbee

    nazbee

    Joined:
    Oct 5, 2016
    Posts:
    9
    Hi,

    Im testing Pool Boss 1.1 with Playmaker 1.8.3 on Unity 5.5.0f3 and having problems with despawning.

    Im using "Pool Boss Spawn" action and it seems to be working correctly. However, only the first pool spawned prefab that triggers a collider is being despawned.

    In my (Collider State) I have a "Trigger Event" action. On Trigger Enter, I filter the Collide Tag, Send Event to a (Despawn State) and Store Collider in a GameObject variable.

    In my (Despawn State) I have "Pool Boss Despawn" calling the stored variable from (Collider State). I then use FINISHED transition to go back to (Collider State) to wait for other collision objects.

    The PlayMaker logic itself works fine if I use "Destroy Object", but "Pool Boss Despawn" only despawns the first object that hits the Trigger Event and ignores the rest.

    Curious- is this a problem with my setup or a bug?
     
  22. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    You should be able to debug this with Playmaker stuff, i.e. are there errors being logged to the Console window that say something about Pool Boss? Or are you reaching the State in Playmaker where it would call PB or no?

    I would think it's a problem with your FSM.
     
  23. nazbee

    nazbee

    Joined:
    Oct 5, 2016
    Posts:
    9
    No errors in the console. Yes, its reaching the state that calls PB. PB Despawn is correctly listing the GameObject variable passed from the Trigger Event Store Collider so it appears to be working.

    Despawn transitions back to the Trigger Event state after each GameObject hits the trigger. Still, only the first pooled object is despawned and the rest are ignored even though they are activating the states and transitions.

    If I swap PB Despawn with Destroy Object, the FSM works correctly. Which leads me to believe it is a PB related issue.

    If you can take a look ill send you a simple file for reproducing.
     
  24. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    I will take a look if the project you sent works for me. Checking shortly.
     
  25. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Pool Boss V 1.1.1 is released! Changelog:

    • Fixed compile error in Unity 5.5
    • Fixed max qty mismatch in Pool Boss Inspector.
    • Fixed error in PrefabIsInPool method.
    • Fixed bug in PoolBossDespawn Playmaker Custom Action that would not despawn 2 different objects if the property changed.
     
  26. nazbee

    nazbee

    Joined:
    Oct 5, 2016
    Posts:
    9
    Thanks, tested the updated script and its despawning correctly now
     
  27. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    No problem.
     
  28. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    V 1.1.2 changelog:
    • Fixed compile errors in Unity 2017 beta.
     
  29. Shadeless

    Shadeless

    Joined:
    Jul 22, 2013
    Posts:
    136
    Hey, so I've been profiling my game in order to reduce garbage, and I noticed that PoolBoss.Despawn caused some garbage.

    0.6Kb from SetParent and like 126b from GetPrefabName.

    I removed the garbage from SetParent, by using
    Code (CSharp):
    1. var rectTrans = trns as RectTransform;
    since Transform can be cast to RectTransform
    instead of GetComponent<RectTransform>();

    To remove the garbage from GetPrefabName, I'm planning to add a string prefabName = null in the Despawn function signature, so I can provide the name myself.

    Cheers
     
    Last edited: May 16, 2017
  30. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Thanks, I've made that change in Pool Boss and Core GameKit now. Why would GetPrefabName cause GC?
     
  31. Shadeless

    Shadeless

    Joined:
    Jul 22, 2013
    Posts:
    136
    @jerotas
    Basically, using transform.name or transform.tag returns a copy of the string which creates garbage... And also strings are immutable so if you also use Substring it also returns a new string object...

    But basically I added the additional parameter in the Despawn function, and I basically provide the name in the Helper functions I use which have the Pool Item Name as a constant.

    Cheers
     
  32. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Ok, it's dumb that you have to do that (constant). I am aware that strings are immutable and all that, this is my day job too. Thanks for giving me that information just in case though.

    Please send me what your changes are so I can incorporate them.

    -Brian
     
  33. Shadeless

    Shadeless

    Joined:
    Jul 22, 2013
    Posts:
    136
    @jerotas
    So I met another issue today. Basically NextPoolItemToSpawn only takes the currently despawned items into account, and it ignores "Allow Instantiate More" if all the prefabs are taken.
     
  34. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Yeah, I wouldn't have thought of that when I coded it up. I can see why that would be needed. I'll do this soon and post back here when it's ready.
     
  35. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Ok, this is fixed. You can email me for the updated method.
     
  36. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Hey,
    Is it possible to display the amount of ram is useed by single and all pooled objects?
    I think the instanced meshes taken into account only.
     
  37. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    I have no idea how that would be possible. I think that's pretty complicated since there may be audio clips, scripts with variables and lots of other separate things to add up, not to mention that the profiler will show "everything", not just what Pool Boss is doing.
     
  38. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    The profiler doesn't help on any build. I require about 7000 different pooled objects They will be "compiled" into blocks and the result will go into the pool again at run-time.

    Did you have free downloadable documentation?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class GetMemoryTest : MonoBehaviour {
    5.  
    6.     public GameObject[,] go;
    7.  
    8.     void Start() {
    9.  
    10.         // Current memory loadup
    11.         long GC_MemoryStart = System.GC.GetTotalMemory(false);
    12.  
    13.         // Declare 200 x 200
    14.         go = new GameObject[200, 200];
    15.  
    16.         for (int x = 0; x <= go.GetUpperBound(0); x++) {
    17.             for (int y = 0; y <= go.GetUpperBound(1); y++) {
    18.                 go[x, y] = GameObject.CreatePrimitive(PrimitiveType.Cube);
    19.                 go[x, y].name = "go[" + x.ToString() + ", " + y.ToString() + "]";
    20.                 go[x, y].transform.position = new Vector3(x, 0, y);
    21.             }
    22.         }
    23.  
    24.         // Lock for GC shortly
    25.         // System.GC.KeepAlive(go);
    26.         long GC_MemoryEnd = System.GC.GetTotalMemory(false);
    27.  
    28.         Debug.Log("Allocated :" + ((GC_MemoryEnd - GC_MemoryStart) / Mathf.Pow(2, 20)).ToString("F3") + "MB : " + (GC_MemoryEnd - GC_MemoryStart) + "Bytes");
    29.     }
    30. }
    31.  
    Some questions..
    + I want to get the nextObject out of the pool , set some required properties then spawn the object. Would that possible?

    + In some cases I require "Allow Instantiate More". This is known about 3-5 seconds before the action happens. Does enlarging the pool works with CoRoutine / Threading or can I extent this functionality by code anyhow?

    thank you.
     
    Last edited: May 27, 2017
  39. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    All the documentation for Pool Boss is included with the download. There is an API website here though:
    https://dl.dropboxusercontent.com/u/40293802/DarkTonic/PoolBoss_API/Index.html

    Get next pool item like this:
    Code (csharp):
    1.  
    2. var nextItem = PoolBoss.NextPoolItemToSpawn("itemName");
    3. /// do stuff, then use it it.
    4. var spawnedItem =PoolBoss.SpawnInPool(nextItem, Vector3.Zero, Quaternion.Identity);
    5.  
    6.  
    Allow Instantiate More does what it says. Why do you need to do anything other than let it do what it does?

    Not sure what to say about the profiling information you are wanting. You have all the source code and the API now. I don't know how to do what you're asking.
     
  40. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Hi.

    Been using Poolboss for couple of weeks now.

    I was wondering if there is option to make the pre-instancing to take over period of time? I do this during initialization loading of the game ofcourse, but I would like to spread the time it takes to do it over frames to make our loading animation to play a bit.

    Any idea?
     
  41. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    There will be soon, but not right now. It's on the roadmap. That's always been a problem of pooling plugins.

    What we do is give them something to read (a game tip / objective) and keep playing music during the transition. Then they don't really even notice it's taking a few seconds.
     
  42. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    It's ok if I only need to display some text over few sec on PC platform. But on console, the app can't be unresponsive for more than 1 sec ( or even less depends ). So everything has to be async and pooling preinstancing has to be done over frames. (maybe a coroutine)
     
  43. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Consoles are very powerful. Unless you're pooling TONS of stuff, Pool Boss alone wouldn't lock up everything for 1 second. I highly doubt. But loading up Audio could take at least that long even without Pool Boss.

    We will get this fix in soon.
     
  44. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Thanks man. Your assets are super awesome. Using Mater Audio as well. But you probably already know this because I nagged you with that asset too :D
     
  45. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    I remember :) Thank you. Will update this thread when the update is released.
     
  46. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I was wondering if it is possible to have multiple pool boss manager objects in the scene. This is because even with the category management , it is sometimes easier to have separate pool game object. Or have some of them only appear on certain scene etc.

    Or can we make them a prefab and then instance them during run time? ( up on instancing it starts preinstancing its objects over some frame of time )

    Master audio does have this feature and it was really useful.
     
  47. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    No, definitely not going to add that. It's far more headache than it's worth for you, the user. Pool Manager had that "feature" and I used it for one of our games. Unfortunately it means having to write a bunch of extra code (not me, but the users), because you now have to tell each game object which one to despawn back to. And you need to keep track of that as well.

    I intentionally didn't add that to Pool Boss because I wanted it to "just work" with worrying about annoying things like that. Trust me, I've been through it and would never choose to do that again. Major major heacache.

    Now what you may appreciate in lieu of that is that I'm adding a "Frames to Initialize" field that defaults to 1. But you'll be able to specify that you want Pool Boss to take 1-100 frames to get fully ready instead of having a really slow frame that locks up the device. That will be in the next update.

    And you can always use a different LevelSettings game object per Scene. Then your Pool Boss is nice and clean.

    -Brian
     
  48. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Well, I was just wondering because Master Audio has this feature, where I can have them on separate game object and they register to the master one as it appear and then deregisters its content upon loading different scene. So I thought it would be nice to have it for the PoolBoss too. For Master Audio, I do not have to care about how the sounds spawn and play it just does, even if I have them separate from the master manager. And they seem to free themselves up upon loading different scene.

    So I have a master manager that is common to the game everywhere, and then have per scene specific ones that loads and unloads per scene requirements.

    If this is not going to happen for pool boss, then I get it. I just thought that since Poolboss is by the same author as master audio, it may share the same methodology behind spawning and despawning.
     
  49. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    It's potentially doable, if I can solve the problems Pool Manager had. If it's like that was, I would not release it because it causes more grief than it's worth. I'll put it on the roadmap.
     
  50. electroflame

    electroflame

    Joined:
    May 7, 2014
    Posts:
    177
    Any chance that Pool Boss can get updated to the latest version? Looks like the version in Core GameKit is up-to-date, but the standalone hasn't been updated in a while.