Search Unity

Pooly - Professional Pooling System

Discussion in 'Assets and Asset Store' started by sharkyro, Mar 7, 2017.

  1. Nixaan

    Nixaan

    Joined:
    May 30, 2013
    Posts:
    118
    Hi,

    I'm thinking of a way to eliminate the need of string manipulations (memory allocations) in spawn/despawn methods. As a result those methods will need a reference to the pool prefab to identify the needed pool. I'm thinking of replacing the Pool dictionary from string, ItemPool to int, ItemPool (int being prefab.GetReferenceId() (or GetInstanceId was it). Another option (still not sure if even possible) is leaving the dictionary alone and create aditional list with reference IDs and from it to get the needed dictionary index.

    So my actual question is: When is the Pool dictionary modified after it is creared/populated and when?

    BTW i don't wat to use the string version of the (de)spawn methods becase the issues with renaming GOs down the line.
     
  2. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hi @Nikaas

    You can either use a string (prefabName) or a Transform (the actual prefab) in order to spawn/despawn.

    The 'optimization' you are talking about (replacing strings with ints) would make the entire system very hard to use and manage. As any developer/designer that uses this system should remember ids instead of prefabNames. There are some limitations that one should take into consideration when developing a system such as this one, thus we will not change the way it works now.

    An average game will pool less than 1000 prefabs, thus implementing your suggestion would make almost no impact performance wise. Sure, in theory, it would be more efficient to remove any type of string manipulators, but in real word scenarios (working with several people on the same project) it would only make the entire system error prone and add useless development times.

    We tested Pooly in a lot of use case scenarios, while doing stress tests, and didn't find any issues with the system. Are you experiencing performance issues with it?
     
  3. Astx

    Astx

    Joined:
    Apr 23, 2015
    Posts:
    9
    Hello @sharkyro!

    Can you, please, explain methods of adding a prefarbs to the Spawner. How i can understand, i must use only prefarbs from scene or assets. Why i can't select inside Spawner pre-added items from the main Pooly?

    Can you, please, add this ability to Spawner? Because, when i have a lot of items with so similar names (in my case it's a lot of different trees) it's too difficult to find and place right items inside the Spawner, i must do the same work twice: firstly select items for Pooly and then find and add the same items to the Spawner. It can be made like the same task at Playmaker: variables can be added directly or you can select it from predefined ones.

    Thank You!
     
  4. Nixaan

    Nixaan

    Joined:
    May 30, 2013
    Posts:
    118
    @sharkyro

    There will be no need for the user to deal with ids. The id is part the pool prefab and that's already passed to the spawn method (just like the name). Only the despawn method will need pool prefab reference passed in addition to the clone reference (that's the actual issue - everything that calls despawn must supply the pool prefab too).

    Anyway IDs are not the problem. I don't ask for you to change anything - instead I have problem understanding if Pool dictionary is modified after it is populated?
     
  5. Astx

    Astx

    Joined:
    Apr 23, 2015
    Posts:
    9
    @sharkyro

    And other small question. Is it possible to change the scale of added prefabs? Changing scale of main Pooly goes to prefabs scale, but also scale they position.
     
  6. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hi @Astx,

    A PoolySpawner can be created and configured in any scene, without any relation to the main pool or any pool extension. Also, if you enable the "Auto add missing items"( in Pooly's Main Pool), the spawner is free to use any prefab because that prefab will automatically be added to the pool at runtime (it is not efficient, but it helps when quick testing). This is why the prefabs for the spawner must be added manually.

    When adding multiple items to either Pooly or to a Pooly Extension we recommend to make use of the drag & drop feature. In that way you can quickly add as many prefabs as needed with just 1 action.
    To make adding prefabs to the PoolySpawner easier, the drag & drop functionality for multple prefabs will be added to it in the next asset release.

    We're not sure we understand your question... Could you please explain a little more?
     
  7. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    @Nikaas
    Yes, the pool can be modified (and it usually is). Either by an extension adding/removing its prefabs or by prefabs being added via the "Auto add missing items" functionality.

    But, again, in order to help, we need to better understand - where does the need to alter such core functionality come from? Have you experienced any issues in terms of performance while using the asset?
     
  8. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    ok I'm in love with this pooling system. Very nice work.

    A question:

    I am using this with 2D and have organized my sorting layers but cannot assign Pooly to a sorting layer. Therefore all of my sorting works except when I spawn a clone it appears underneath everything else. I did try to do the following tp parent the clone (my player shoots a bullet which comes from the pool):

    Pooly . Spawn ( string itemName , Vector3 position , Vector3 rotation , Transform parent);

    Pooly spawns it just fine but even though my player is on it's own sorting layer, the spawned clones still are underneath everything else.

    Any ideas?
     
    Last edited: Nov 11, 2017
  9. Astx

    Astx

    Joined:
    Apr 23, 2015
    Posts:
    9
    I mean: we have position, rotation and even position offset for spawning routines, but don't have a scale. Sadly, when you use assets from different sellers, they mostly don't use same scale for prefabs and we need update it on the fly.
     
    sharkyro likes this.
  10. Nixaan

    Nixaan

    Joined:
    May 30, 2013
    Posts:
    118
    No, I don't have a problem. Instead I was curious how Pooly finds the needed pool because my spawn system needed a reference to the prefab. So I thought it worths nothing to remove the strings and test the speed difference as I already had the needed tradeoff (a pool prefab reference in the despawners).

    BTW In the end I was able to do it. The gain was ~15% speedup and no allocations down from 1.2MB (for a PC build and 10k spawn+despawn), but I'm leaning toward the freedom that the no pool reference gives.
     
  11. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hi @starfoxy,

    What you have described could be an issue either with the sorting layers or with the order in layer configuration. Lastly, if renderers have the same sorting layer and the same order in layer, the distance to the camera is taken into consideration. We recommend that you double check the sorting layer & order in layer configuration of the prefabs that you need to spawn.

    Rendering is not a trivial thing and Pooly will not interfere with any such configuration. Whenever you need to make changes to a spawned clone upon spawning, you can write your own functionality in an OnSpawn() method in your own custom script.

    Cheers,
    Alex.
     
  12. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    @Astx we appreciate your suggestion. The option to set the clone's scale on spawning will be included in the next version of Pooly.

    Cheers,
    Alex.
     
    Astx likes this.
  13. Astx

    Astx

    Joined:
    Apr 23, 2015
    Posts:
    9
    Thank You! And other small request for feature updates: two spawning actions for PlayMaker has "Parent Game Object". Can You, please, add the same option to the main Pooly Spawner and make new Despawner "under parent".
    I can do all this things by hand, but it will be cool to have it premaded inside asset. Thank You!
     
  14. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    @Astx
    Good point, this will also be supported.

    Unfortunately, this will not be implemented. Going through all the children of a GameObject in order to despawn them is not really a good approach when it comes to performance. Plus there needs to be additional overhead to check if a child GO is actually a spawned clone or not. While this approach might be something suited for your current project we don't think it would be suitable as a general pooling solution.

    Alternatively, you might want to use the provided methods DespawnAllClonesInCategory() or DespawnAllClonesOfPrefab().
     
    Astx likes this.
  15. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    I am using Pooly with the Pooly Spawner. This works fine. I am trying to check for a collision with a spawned object and my bullet and it isn't working.

    The script on my bullet (this worked fine when it wasn't in the pool so I assume I am grabbing the name wrong from the cloned gameobjects):

    void OnCollisionEnter2D(Collision2D coll){
    if (coll.gameObject.name == "theEnemy"){
    Debug.Log(coll.gameObject.name);
    Pooly.Despawn(gameObject.transform);
    }
    }

    How can I refer to coll.gameObject.name for a cloned object from the pool?
     
    Last edited: Nov 20, 2017
  16. Bitboys

    Bitboys

    Joined:
    Apr 22, 2015
    Posts:
    156
    Hello. I´m trying to spawn the main pool prefabas from code but don´t seams to work. The documentation algo is a bit confused. Thanks
     
  17. Bitboys

    Bitboys

    Joined:
    Apr 22, 2015
    Posts:
    156
    I´m having problems to instantiate some particles at raycast hit point
     
    Last edited: Nov 20, 2017
  18. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    @starfoxy
    In order to make clone management clear and debugging much easier, Pooly renames all instantiated clones as "PrefabName (Clone X)", where PrefabName is the name of the originating prefab and X = the clone's number.

    In your case you can use Pooly's helper method that returns the name of the prefab that was used to spawn the clone:
    Code (CSharp):
    1. Pooly.GetPrefabNameFromClone(Transform clone);
    As the method shown above does add a little overhead, a cheaper (in terms of performance) alternative would be to despawn based on the Tag.

    Cheers,
    Alex.
     
    Last edited: Nov 20, 2017
  19. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hi @Mijail_Bitboys

    We have tested our asset and it is working on all supported Unity versions. Can you please be more specific regarding the problem(s) you have encountered?

    Cheers,
    Alex.
     
  20. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184

    Thanks Alex, I'm still not totally clear on this.

    How can I check if the bullet is colliding with a specific game object? I'd like to achieve this with as little overhead as possible.

    Code (CSharp):
    1. void OnCollisionEnter2D(Collision2D coll){
    2. if (coll.gameObject.name == "theEnemy"){
    3. Debug.Log(coll.gameObject.name);
    4. Pooly.Despawn(gameObject.transform);
    5. }
    6. }
    How would you rework the code shown to address various clones? I'm more interested in how to check a specific collision but even so, still not clear on how a tag would help with despawning.

    I am also open to suggestions as to a different approach to tracking collisions with Pooly that have worked for you.
     
    Last edited: Nov 22, 2017
  21. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    @starfoxy

    You only need to change the "if" clause in your code.

    To take action based on the name of the colliding object (if it is a spawned clone!):
    Code (CSharp):
    1. if(Pooly.GetPrefabNameFromClone(coll.transform)== "theEnemy")
    2. { /* Do something */ }
    If you want to take action based on the tag of the colliding object:
    Code (CSharp):
    1. if(coll.gameObject.tag == "EnemyTag")
    2. { /* Do something */ }
    If you apply the "EnemyTag" to multiple GameObjects, colliding with any of them would cause the code inside the "if" statement to run. To learn more about tags, please see the manual: https://docs.unity3d.com/Manual/Tags.html
     
  22. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    Fantastic. Thanks for the help Alex! cheers!
     
    sharkyro likes this.
  23. twitchfactor

    twitchfactor

    Joined:
    Mar 8, 2009
    Posts:
    356
    Hello, sharkyro, I purchased Pooly and it seems to be pretty nice and a good fit for my game, except I keep getting this error, every time I reset my level.

    I am using
    as a quick and dirty reset for my level.

    Everything reloads and resets, except Pooly, which gives me the above error and stops functioning.

    I'd hate to have to rip out Pooly and start over with another pooling solution.

    Any help, greatly appreciated.
     
  24. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hello @twitchfactor

    Indeed, there is an issue with the singleton implementation in Pooly v1.0. Please drop us an email with a support request so that we can send to you a patch.

    Cheers,
    Alex.
     
  25. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    This may be a long shot but does anyone have any insight to using Behavior Designer with Pooly?
     
  26. f1chris

    f1chris

    Joined:
    Sep 21, 2013
    Posts:
    335
    Hi @sharkyro,

    I love your asset and it's so efficient. Probably more a suggestion than a question. Anyway we can define a spawning area ? I know it's possible in the Spawner Component to add multiple locations but it would be so convenient to define boxes ( areas) and just drag them.

    Or, keep those location be able to spawn randomly in a certain radius.

    thx
     
  27. tcmeric

    tcmeric

    Joined:
    Dec 21, 2016
    Posts:
    190
    Not sure if you came up with a solution to this? I have written many iterations for other assets for playmaker (and I use pooly). Just started using BD as well. If I make any integrations, Ill post them here. Might be a month or two however.
     
  28. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hi @f1christian,

    At the moment, it's not possible to define a spawning area/volume. It's definitely an interesting idea, but the implementation is far from trivial, so we can't make any promises on this.

    The fastest way to achieve your goal would be to simply move the spawner around as needed and have it spawn at its own location.
     
  29. f1chris

    f1chris

    Joined:
    Sep 21, 2013
    Posts:
    335
    Question : if using the onStart event of the Spawner, can i move the spawner location there ?

    I can understand a full area/volume solution if far from trivial. Is an interim solution would be to add a radius parameter , like let say 10 and spawn it somewhere randomly between (x-10,x+10) and (z-10,z+10) ? ( let's keep the Y to the location transform you already have).
     
  30. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    OnSpawnStart is invoked only once - when spawning starts.

    To achieve the desired effect, you simply need a "mover" script on the spawner's GameObject that moves the spawner around using exactly the algorithm you described. What you can do is to start a coroutine in the "mover script" that moves the spawner around with the same frequency it is configured to spawn (you can even make it so that this coroutine starts based on OnSpawnStart).
     
  31. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hello everyone!

    We're very excited to announce Pooly version 2.0! Check out the introduction to the new version and the tutorial on how to upgrade on our YouTube channel:

    Pooly v2.0 Introduction:


    Upgrade Guide for Ez assets - from version 1.x to version 2.x:


    Cheers!
     
    Last edited: Jan 30, 2018
    blitzvb likes this.
  32. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hi @tcmeric

    Did you get the private message we sent to you? In case you missed it, check your forum inbox and let us know what you think :)

    Cheers!
     
    tcmeric likes this.
  33. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    Is there any issue with using Pooly with Unity 2017.3.1f1 ? I installed Pooly 2.0 and it gave me a warning that it is using old API's and needed to convert the Pooly scripts to using the new API's. Any issues that you know of on 2017.3.1f1 ? cheers!
     
  34. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hi @starfoxy

    That import warning is normal because Pooly was also released with support for Unity 5.6 and some API needs to be automatically updated by Unity when importing in 2017.x. No worries - at this time, there are no known issues with Pooly in Unity 2017 :)

    Cheers,
    Alex.
     
    blitzvb likes this.
  35. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    Great, thanks Alex! Please keep up the awesome work with Pooly. I love it!
     
    sharkyro likes this.
  36. kulesz

    kulesz

    Joined:
    Jul 1, 2012
    Posts:
    140
    Does pooly create some folders on its own? After each application run I have more and more empty directories:
     

    Attached Files:

  37. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hi @kulesz

    Indeed, there seems to be a problem when the /Ez/Pooly folder is moved - thanks for letting us know. Please send us a support email so that we can send you the fix for this issue.

    The quick fix is to restore the folder to its default location under /Assets/Ez/Pooly.

    Best Regards,
    Alex.
     
  38. blitzvb

    blitzvb

    Joined:
    Mar 20, 2015
    Posts:
    284
    Arf so I have that bug too. Keep us updated even the fix come out.
     
  39. kulesz

    kulesz

    Joined:
    Jul 1, 2012
    Posts:
    140
    Thanks, I've sent you an e-mail.
     
  40. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hi @blitzvb! Yes, we've developed a hotfix, please drop us an email at our support address so we can send it to you.

    @kulesz We've sent the patch to you, let us know if you encounter other difficulties.

    We will release an official patch to fix this issue and a couple of other bugs we've run into. If anyone needs the fix before the official patch becomes available through the asset store, please email us.

    Cheers,
    Alex.
     
    Last edited: Mar 6, 2018
    blitzvb likes this.
  41. Mark_T

    Mark_T

    Joined:
    Apr 25, 2011
    Posts:
    303
    Guys, you should put the Asset Store link to your product in the first post. It's very inconvenient for a new users to find it.

    I've just started with Pooly and noticed you have new tutorials. Any changes in the Playmaker integration?
    Thanks!
     
  42. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Now why didn't we think of that? It's done! :)

    There are some additions to PlayMaker actions compared to Pooly v1.x. Some actions have new parameters to support new functionality (like scaling a clone after spawning it). There are also some new actions dedicated to controlling a Pooly Spawner from PlayMaker FSM. Any existing FSM configuration should not be affected by upgrading to v2.x, however.

    We will definitely be covering the updated PlayMaker actions in future videos.
     
    Last edited: Mar 7, 2018
  43. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    hey guys, I am using the newest version of Pooly. In VSCode when:

    using Ez.Pooly;

    and then
    Pooly.Spawn(...);

    It is showing an error red underline on Ez. and then also on Pooly. but it all runs just fine.

    How can I address this as I'd rather not see a false error warning in the IDE.

    Thanks!

    -----edit ----- leaving this here for others -----

    Save your project, scripts, etc. Restart VSCode. All solved. Not a problem with Pooly but a quirk of VSCode/Unity. :)
     
    Last edited: Mar 11, 2018
    sharkyro likes this.
  44. tsx_hypernova

    tsx_hypernova

    Joined:
    Oct 4, 2016
    Posts:
    1
    Does Pooly have built-in support for pooling networked objects ?
     
  45. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hi @tsx_hypernova

    Right now, Pooly does not have built-in networking support. We are investigating some options for implementing this, but we can't make any promises at the moment.
     
  46. BryanO

    BryanO

    Joined:
    Jan 8, 2014
    Posts:
    186
    Is there a way to make spawning and despawning proximity based?
     
  47. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    Hi @BryanO

    There are a few ways to implement that - for example using trigger-based despawners. Can you please give more details on what you want to achieve?
     
  48. BryanO

    BryanO

    Joined:
    Jan 8, 2014
    Posts:
    186
    Sure - Player enters sphere collider Creatures spawn - player leaves sphere collider creatures despawn
     
  49. sharkyro

    sharkyro

    Joined:
    Mar 15, 2014
    Posts:
    127
    This is quite simple - take a look at this tutorial we've just released on how to spawn an item and have the player pick it up:
    The concepts are the same and can be aplied in your case.

    For this, you need to despawn based on TriggerExit (or CollisionExit, if you are using collisions). If each creature has its own trigger/collider you can just use the Pooly Despawner for this.

    If you have just 1 global trigger/collider, you can write your own script that despawns the target clones when the player exits (there are methods in Pooly to help with despawning without having a direct reference to the clones: Pooly.DespawnAllClones(), Pooly.DespawnAllClonesInCategory() or Pooly.DespawnAllClonesOfPrefab()). The script would be something very simple like:

    Code (CSharp):
    1. public class CreatureDespawner : MonoBehaviour
    2. {
    3.     private void OnTriggerExit(Collider other)
    4.     {
    5.         // test if "other" collider is actually the player
    6.         Pooly.DespawnAllClonesInCategory("Creatures");
    7.     }
    8. }
    Cheers,
    Alex.
     
  50. BryanO

    BryanO

    Joined:
    Jan 8, 2014
    Posts:
    186
    Thanks I get the despawing bit the script is a great example - but I dont understand how to start a spawner to start spawning or stop it with the trigger ... Is it this script attached to spawner object with a collider trigger object attached?

    Code (CSharp):
    1. using Ez.Pooly;
    2. public class StartSpawner : MonoBehaviour
    3. {
    4. PoolySpawner spawner;
    5. private void OnTriggerEnter(Collider other)
    6. {
    7. // test if "other" collider is actually the player
    8. spawner.StartSpawn();
    9. }
    10. }