Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

PoolManager [By Path-o-logical-Games]

Discussion in 'Assets and Asset Store' started by Rafes, Sep 13, 2011.

  1. jvil

    jvil

    Joined:
    Jul 13, 2012
    Posts:
    263
    Always can download a version of Unity 3.x and have the 2 versions installed on different folders: http://unity3d.com/unity/download/archive

    I'm another Unity 3.x user and I can say PoolManager it's a must-have plugin, but this lack of support for Unity 3.x don't make this plugin as great as could be.
     
  2. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    As I said we will continue to support Unity 3.x users. If any bug is reported we will make a branched 3.x compatible package available. If anyone wishes to purchase PoolManager from our website, they can email us for any version they might need.

    As for new users, only about 5 or 6 in the last two few months have been Unity 3x users. I am happy to offer personal service and support for these new users to get them going. In the same period we have added hundreds of new 4x users.

    With Unity 4.3 due out any time now we wanted to take the opportunity to do this long-requested update for namespacing that wasn't possible before (as well as a number of things for our other packages, all of which are using the same namespace as of their version 5.0 releases as well). In the end we will be able to provide a better experience for our users.
     
  3. Bradamante

    Bradamante

    Joined:
    Sep 27, 2012
    Posts:
    300
    I've started using PoolManager in my game and I'd like to know if PM provides convenience functions like

    Code (csharp):
    1. public Transform spawnFromPoolAndReparent ( string poolName, string prefabName, Transform spawnParent ) {
    2.        
    3.         Transform poolLink = PoolManager.Pools[ poolName ].prefabs[ prefabName ];
    4.         Transform poolItem = PoolManager.Pools[ poolName ].Spawn( poolLink );
    5.         poolItem.parent = spawnParent;
    6.         poolItem.localPosition = Vector3.zero;
    7.         return poolItem;
    8.     }
    or

    Code (csharp):
    1. public Transform spawnFromPool ( string poolName, string prefabName ) {
    2.        
    3.         Transform poolLink = PoolManager.Pools[ poolName ].prefabs[ prefabName ];
    4.         Transform poolItem = PoolManager.Pools[ poolName ].Spawn( poolLink );
    5.         poolItem.localPosition = Vector3.zero;
    6.         return poolItem;
    7.     }
    or if I just over-looked them? Or am I using PM wrong?
     
  4. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    Hi,

    There is nothing wrong with these at all. We just haven't gone so high-level since these are rather specific behaviors. When we provide something in the API, we need to add a bunch of overloads as well. For example, what if someone wants to re-parent but doesn't want to re-position.

    I think we can provide all the same functionality directly in Spawn() to keep it lower-level and flexible. I'm prepping a release now. I'll try and get it in.

    Instead of SpawnFromPool, We could have SpawnPool.Spawn(string prefab),
    Instead of SpawnFromPoolAndReparent, we could add a "parent" argument to Spawn as well, but that would mean doubling the overloads so every permutation has the parent option. That would allow for everything you show though, e.g. (You wouldn't need the function, but just to show where the variables end up...)
    Code (csharp):
    1.  
    2. public Transform spawnFromPoolAndReparent(string poolName, string prefabName, Transform spawnParent)
    3. {
    4.      return PoolManager.Pools[poolName].Spawn
    5.      (
    6.          prefabName,
    7.          spawnParent.position,
    8.          spawnParrent.rotation,
    9.          spawnParent                 // <--Parent arg.
    10.      )
    11. }
    12.  
     
    Last edited: Sep 18, 2013
  5. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    Good news! I was able to add 8 new methods - 6 new Spawn() overloads and 2 new Despawn() overloads.

    You will be able to...
    • Spawn using just the prefab name. The cached reference to the Transform will be fetched from the SpawnPool.prefabs dictionary, which is very little overhead
    • ​Spawn with an optional parent. This lets you do two things: 1) Pass a Transform and the instance will be parented under it. 2) Pass 'null' and the instance will be parented to nothing (the scene root).
    • Despawn with an optional parent. This is the same as the new Spawn option but it lets you choose a parent to be set just before despawn
    All of these are available for every variation (overload) of the methods except for the ParticleSystem or ParticleEmitter overloads. For example, you can Despawn with a delay and still pass a parent. You can also combine them and spawn using the prefab name and pass a parent.

    I hope these convenience methods will make PoolManager that much easier to use without any major added complexity for the API.

    This will be in the next release coming this week, version 5.1.0. (This is available to our direct users now)
     
    Last edited: Sep 20, 2013
  6. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,311
    Can you include an example scene with the new features ?
     
  7. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    Hi,

    I already released this one, but it is something that could be done in the future. However, I didn't think it would need one just because there are no new methods, just new overrides of existing API methods. I'm not sure what I would put in an example scene. I updated the code documentation which I hope will be more informative:
    http://docs.poolmanager.path-o-logical.com/code-reference/spawnpool/spawnpool-spawn
    http://docs.poolmanager.path-o-logical.com/code-reference/spawnpool/spawnpool-despawn

    Remember that these are convenience additions (meaning you could have done this stuff before on your own, but this update makes it a little easier). They are the sort of thing that are great to have when you go looking but not something you will need to know in order to design your basic game logic.

    Also, If you are using VisualStudio (Mono might do it to), you will see the overload list and documentation when you start typing Spawn() or Despawn().
     
    Last edited: Sep 20, 2013
  8. Bradamante

    Bradamante

    Joined:
    Sep 27, 2012
    Posts:
    300
    Thanks for your work, but don't put something in just because I said so. I don't consider myself a terribly advanced Unity user, so don't take my word for it.

     
    Last edited: Sep 20, 2013
  9. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    No worries. A good idea is a good idea ;)
     
  10. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
  11. Bradamante

    Bradamante

    Joined:
    Sep 27, 2012
    Posts:
    300
    Hi,

    you did not add overload methods for

    Code (csharp):
    1. Spawn(ParticleSystem prefab, Vector3 pos, Quaternion rot)
    Is there a specific reason for that? I could use a

    Code (csharp):
    1. Spawn(ParticleSystem prefab, Vector3 pos, Quaternion rot, Transform newParent)
    right now ;)
     
  12. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    I'll add a ticket for the next release now. If there WAS a good reason, I'll let you know ;)

    For now, please use (pseudo code):
    Code (csharp):
    1.  
    2. inst = ...Spawn(ParticleSystem prefab, Vector3 pos, Quaternion rot);
    3. inst.transform.parent = newParent;
    4.  
     
  13. Bradamante

    Bradamante

    Joined:
    Sep 27, 2012
    Posts:
    300
    Using PM to spawn GameObjects with ParticleSystems (and nothing else) I seem to have trouble with the automatic despawn. Mostly it works fine, with lot's of stuff being spawned and de-spawned correctly, but sometimes I get a warning a la

    "PoolManager timed out on Particle System XYZ, waited for 60 seconds."

    What's the typical cause for that?

    Btw, I wonder if adding

    Code (csharp):
    1. AudioSource src = PoolManager.Pools["Sounds"].Spawn( AudioSource prefab )
    would make sense. Where PM treats a GameObject with a AudioSource on it like it would a ParticleSystem, i.e. de-spawning it automatically when it finishes.
     
  14. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    Hi,

    This is a safety measure to ensure users aren't spawning particles that shouldn't be listened to, since each one starts a co-routine to listen for the death of the last particle. If someone didn't understand the difference between passing a Transform (spawn and done) vs a Particle System (spawn and listen) they might end up with the equivalent of a memory leak in some frindge situations.

    If you have particles going for more than a minute that you want PoolManager to listen to, there is a value at the top of SpawnPool you can change right now to get it working. Then, I'd be happy to extend this time limit if you think it is too short.

    That is a cool idea. We are just getting in to Audio in our current game so I'll look for an opportunity to extend PoolManager to assist in this area. Thanks!
     
  15. Bradamante

    Bradamante

    Joined:
    Sep 27, 2012
    Posts:
    300
    Hi,

    no, that's not it. I'm pretty sure my particles should never take longer than a few seconds. Basically I see getting this message as an error. My particles often have child transforms with their own ParticleSystems - could that be a cause?

    Surely I don't have enough particles in the queue (it's set to 10 right now), but that shouldn't be the cause, right? I plan on increasing this number in the future, but first I need more testing to get a feeling for a good count.

    For sound de-spawning I have this on all my sound GameObjects:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. using PathologicalGames;
    6.  
    7. public class PooledSound : MonoBehaviour {
    8.    
    9.     private Transform tf;
    10.     private AudioSource audioSrc;
    11.    
    12.     void Awake () {
    13.         tf = transform;
    14.         audioSrc = GetComponent<AudioSource>();
    15.     }
    16.  
    17.     public void OnSpawned () {
    18.  
    19.         audioSrc.Play();
    20.         Invoke( "delayedDespawn", audioSrc.clip.length );
    21.     }
    22.    
    23.     public void OnDespawned () {
    24.        
    25.         audioSrc.Stop();
    26.     }
    27.    
    28.     private void delayedDespawn () {
    29.        
    30.         PoolManager.Pools["Sounds"].Despawn( tf );
    31.     }
    32. }
    33.  
     
    Last edited: Nov 26, 2013
  16. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    I checked and I'm not sure how you could be getting this message unless the particles are alive for at least 60 seconds (I changed this to 300 seconds by the way. This should still offer debuggable protection but allow 5min effects, which I think pretty long.) The counting coroutine starts when spawned and the coroutine quits if the instance is despawned; directly or by all particles dying.

    To help further I think I'd need a stripped down project the reproduces the issue. Please post on our forums or email support@path-o-logical.com

    Thanks for sharing! I'd be happy to add this. If you wouldn't mind beta-testing the first version, please email support@path-o-logical.com and let me know.

    Cheers,
     
  17. Bradamante

    Bradamante

    Joined:
    Sep 27, 2012
    Posts:
    300
    Well if I change your time out warning to print out the Particle Name I get something like:

    Code (csharp):
    1. [your message starts] MediumExplosion(Clone)(148) [your message continues]
    with 148 being replacable by any higher index you want. What I am saying is that I know as much as before. The PoolManager times out with some random particle. As if the Coroutine was ended from the outside (is that even possible?) or the Manager did not pick up the Particle duration correctly (is that possible?).

    Notice I use a ParticleSystem, not a ParticleEmiter (is that it?).

    I guess I will return to a manual despawn solution, similar to the audio spawn/despawn code posted above :(
     
    Last edited: Dec 1, 2013
  18. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    The co-routine polls Unity's ParticleSystem.IsAlive (http://docs.unity3d.com/Documentation/ScriptReference/ParticleSystem.IsAlive.html) which is supposed to factor in child systems. If you've found a better way, please let me know.

    Did you see in my last post that I mentioned I have a beta version with AudioSource handling if you want to test it out? Please email support@path-o-logical.com with your order number and I'll email it to you.
     
  19. Bradamante

    Bradamante

    Joined:
    Sep 27, 2012
    Posts:
    300
    Yes, I did read that, but I don't really have a need for that, since my manual solution works fine. Also I can't send you a isolated reproduction setup - too much work for no guaranteed gain.

    Another thing. When I go to SpawnPool.cs, line 100 and change maxParticleDespawnTime to 20f, and do

    Code (csharp):
    1. string.Format
    2.                         (
    3.                             "SpawnPool {0}: " +
    4.                             "Timed out while listening for all particles to die ({1} sec). " +
    5.                             "Waited for: {2}.",
    6.                             this.poolName,
    7.                             this.maxParticleDespawnTime,
    8.                             emitter.name
    9.                         )
    on line 921, it still prints:

    Code (csharp):
    1. SpawnPool Explosions: Timed out while listening for all particles (60 sec) to die. Waited for: MediumExplosion(Clone)001.
    on the Console. How come? How come I set 20 seconds and the print still says 60?
     
    Last edited: Dec 2, 2013
  20. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    My mistake. It thought you wanted this feature. Let me know if you change your mind. It will be released in the next version regardless.

    I have no idea. The field is only set once (when defined at the top of the class) and only used twice. It is never set again from what I can see. You might want to search your project in case you used it somwhere? It is public so you don't have to change it in the file. You could add it to any script (probably in Awake()).
     
  21. Todd-Riggins

    Todd-Riggins

    Joined:
    Oct 25, 2012
    Posts:
    6
    Hi Rafes, I have imported pool manager 1.5.1 into my project ready to use with Unity version 4.3.1 and I get these two warnings:

    Assets/Editor/PathologicalGames/Common/PGEditorUtils.cs(61,26): warning CS0618: `UnityEditor.EditorGUIUtility.LookLikeControls(float)' is obsolete: `LookLikeControls and LookLikeInspector modes are deprecated. Use EditorGUIUtility.labelWidth and EditorGUIUtility.fieldWidth to control label and field widths.'

    Assets/Editor/PathologicalGames/Common/PGEditorUtils.cs(1010,26): warning CS0618: `UnityEditor.EditorGUIUtility.LookLikeInspector()' is obsolete: `LookLikeControls and LookLikeInspector modes are deprecated.'

    Should I be concerned about these warnings? I'm not familiar with these 'LookLike' unity methods to even try to fix it on my end at the moment. Thanks.
     
  22. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    Hi,

    We are aware of this change. There should be no problem using PoolManager. They are just annoying. These are Editor specific changes, so at worst, an inspector might not look right. It won't affect how PoolManager functions. We will be updating to Unity 4.3 soon to silence them.
     
  23. LutinMalefique

    LutinMalefique

    Joined:
    Nov 14, 2012
    Posts:
    6
    Hi Rafes,

    I've got a problem with PoolManager. It's a bug i've notice only a few days ago, so i don't know if it's due to new version of Unity or PoolManager.
    I use poolmanger spawn code since the begining of my project, with simple code and basic spawnpool set up

    So my problem is, when i spawn objects everything is ok but, when my 10 or 20 or more preload objets have been spwaned, and despawn, the next time i want to spawn them they don't appeared where they have to but, where the previous object was despawned...

    Any ideas....
     
  24. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    Hi,
    ]
    PoolManager doesn't do any work it doesn't have to. Think of each spawned instance as a new "thing", but some states need to be handled depending on your game's needs. You should provide Spawn() with a position and rotation, just like you would with Instantiate
     
  25. LutinMalefique

    LutinMalefique

    Joined:
    Nov 14, 2012
    Posts:
    6
    Sorry, i've not been clear, that what i do. Here a screenshot :
    $spawnBug.jpg

    My problem is, when all the prefabs in the spawnpool have been spawned and despawned once, the next time i want to spawn a prefab, it's spawned at it's "despawn position" instead of the spawn position....So my code is the same, so i don't why it doesn't work twice. The bug does not occur every time, sometimes 2 or 3 npc spawned in the correct position like the next one but that one does not move as it should.
     
  26. LutinMalefique

    LutinMalefique

    Joined:
    Nov 14, 2012
    Posts:
    6
    Forget It, i think i found what was wrong in my code....wrong line in the wrong place...:-?
     
  27. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    880
    hi sorry i don't understand despawn
    i do
    myInstance = PoolManager.Pools["decor"].Spawn(obj);

    and PoolManager.Pools["decor"].Despawn(myInstance);

    and i got

    KeyNotFoundException: A Pool with the name 'decor' not found.
    Pools=[]
    PathologicalGames.SpawnPoolsDict.get_Item (System.String key) (at Assets/Plugins/PathologicalGames/PoolManager/PoolManager.cs:318)
    Spawned.OnDisable () (at Assets/EndlessUniverse/Spawned.js:300)

    what's it's want say

    i got this one too

    MissingReferenceException: Make sure you didn't delete a despawned instance directly.
    PathologicalGames.PrefabPool.SpawnInstance (Vector3 pos, Quaternion rot) (at Assets/Plugins/PathologicalGames/PoolManager/SpawnPool.cs:1386)
    PathologicalGames.SpawnPool.Spawn (UnityEngine.Transform prefab, Vector3 pos, Quaternion rot) (at Assets/Plugins/PathologicalGames/PoolManager/SpawnPool.cs:417)
    PathologicalGames.SpawnPool.Spawn (UnityEngine.Transform prefab) (at Assets/Plugins/PathologicalGames/PoolManager/SpawnPool.cs:476)


    and i not understand
     
    Last edited: Jan 20, 2014
  28. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    For the first one, it looks like you never created a pool called "decor". Make sure you create the pool before using it.

    For the second, make sure you aren't calling Destroy on an object you Spawn, or on the parent of an item you Spawn. If you are reparenting to an object you want to destroy, make sure you unparent it before destroying it, as the Destroy will destroy all children as well.
     
  29. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    880
    $6rBVa.png
    i need create in script too ?
     
  30. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    Thanks for positing a response niosop2. Good answers.

    Kilik128 I saw you posted these questions to our forums, so I'll keep my reply here brief for anyone scanning this thread:

    If you definitely created the pool and are trying to use it from Awake() in one of your scripts, your script may be running before PoolManager's SpawnPool's Awake(). This is a classic problem in Unity with various solutions. I am also looking in to a way to use an event delegate to create a post-initialization event at the PoolManager level to run code when a pool is done being created.
     
  31. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    We just released an update to support Unity 4.3 and address a number of requests made by our users. See the release notes here:
    http://forums.support.path-o-logical.com/viewtopic.php?f=3&t=31

    Also, please tell your friends and colleagues our Pool, Target, Constrain Bundle is being featured in the Unity Madness Sale right now!!!

    Or get the same discount at our store using this 50% off coupon: CPN51670212185

    To use it, go to http://packages.path-o-logical.com and click on the Bundle "Get It Now" link. Enter the quantity you wish to purchase and the coupon and click "Update Cart" to verify you are receiving the discount.
     
  32. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    The new version is now available in the AssetStore.
     
  33. assaf-cohen

    assaf-cohen

    Joined:
    Sep 27, 2013
    Posts:
    91
    Hi guys,
    I'm not sure if it's a bug in Unity or in PoolManager -
    Unity editor crashes when I'm calling a (c#) method that's calling Despawn without delay as an event from animation.

    It works well if I add a time delay - for example - PoolManager.Pools["Weapons"].Despawn(gameObject.transform, 0.5f)
    (also, "Destroy(gameobject)" without time delay works well)

    Can you please have a look?
     
  34. RodolfoLasparri1

    RodolfoLasparri1

    Joined:
    Feb 24, 2013
    Posts:
    14
    Hey fellas, great job on this tool

    I have a question, when you .Spawn a ParticleSystem, you can't call it using the name as a string, and you can't get a .prefab("name") because it requires a Transform

    how should I go about spawning the ParticleSystems by name?

    thanks!
     
  35. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    Hi,

    Please post to our forums at support.path-o-logical.com/forums and include a little more detail on what you mean by "an event from animation" as well as a bit of your code which causes your issue.

    We prefer to do more detailed support at our forums because it may help someone else (included in the search feature) and reduces emails to others who follow this thread. We do appreciate your report though and look forward to help you resolve your issue.
     
  36. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    Hi,

    To create "overload" versions of a method a unique method signature (arguments) is required. The string convenience overloads are provided for the widest use case, Transforms. We can't also use the same signature with a string for AudioSource or ParticleSystem handling. The most important thing though is that these ARE just convenience overloads. They are not necessary to do the same thing from outside PoolManager. To use a string-based workflow with a ParticleSystem, all you have to do is get the prefab, get the prefab's ParticleSystem component, and then use that with Spawn(). E.g.:
    Code (csharp):
    1.  
    2. SpawnPool pool = PoolManager.Pools["Effects"];
    3. Transform prefab  = pool.prefabs["ParticlePrefab"];
    4. ParticleSystem prefabPart = prefab.GetComponent<ParticleSystem>();
    5. ParticleSystem instPart = pool.Spawn(prefabPart, Vector3.Zero, Quaternion.Identity);
    6.  
    For what it's worth, in general I recommend avoiding string-based workflows of all kinds unless it really solves a particular situation. References are always faster and easier to maintain.

    I hope this helps!
     
  37. RodolfoLasparri1

    RodolfoLasparri1

    Joined:
    Feb 24, 2013
    Posts:
    14
    Thanks Rafes!

    indeed, it's very convenient to use strings, I think I am going to build a static class with references so I can call a method to handle spawning particles on any random object

    thanks for the clarification :)
     
  38. Bradamante

    Bradamante

    Joined:
    Sep 27, 2012
    Posts:
    300
    Is PoolManager compatible with the echoLogin CORE Framework?

    Reason I ask is that in their documentation they are saying that

    Would that interfere with PoolManager, where objects are generally inactive when they reside in the pool?
     
  39. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    The best I can say is "it depends". It sounds like they are talking about just the initial frame when the instance is created? There used to be (and maybe still is) a strange problem with Start() where it doesn't always run if the instance isn't active on the frame immediately after instantiation.

    The docs you quoted make it sounds optional though?

    While it does "depend", I'd be happy to work with you via support@path-o-logical.com to make it work. If there is no way to make it work, I can refund your purchase.
     
  40. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,131
    Good evening fellow PoolManager users! I'm having a problem with the combination of PoolManager and Mechanim. I'm 99% positive that someone on this thread has solved the issue before. Please take a quick look at my other thread I just started here and let me know.

    Thanks in advance!
     
  41. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    The way you describe it it does seem like a bug in the Animator component.

    Maybe it is some sort of race situation? You could try launching a co-routine that waits for a frame, or even a second, before triggering the idle animation; just as a test.

    Another idea: Can you force the lid closed in OnDespawned so it is already closed OnSpawned?

    I doubt it matters, but just for the sake of performance, are you caching the Animator component in Awake() and then using it in other places? e.g. (Untested. Just typed this.)
    Code (csharp):
    1.  
    2. [RequireComponent(typeof(Animator))]
    3. public class Coffin : Monobehavior
    4. {
    5.     private Animator animator;
    6.  
    7.     private void Awake()
    8.     {
    9.         this.animator = this.GetComponent<Animator>();    
    10.     {
    11.  
    12.     private void OnSpawned()
    13.     {
    14.         this.animator.Play("Idle");
    15.     }
    16. }
    17.  
     
  42. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,131
    Thanks for the reply Rafe. I had already tried all those things. Pretty frustrating.
     
  43. Bradamante

    Bradamante

    Joined:
    Sep 27, 2012
    Posts:
    300
    For the n-th time I am setting up my Pool Manager objects in the scene. That's why I wanted to make a request. Could the SpawnPool script please get some input field where you set how many pre-pooled instances of each object in that SpawnPool there will be?

    Let's say I add 70 space ships to my "SpaceShips" pool, each will have 25 instances. Kind of a pain to enter the number 25 70 times ...
     
  44. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    Do you mean you want a global preload amount field? Meaning a single field on the spawn pool that you set and then all PrefabPools automatically use this number instead of the "local" one set in its own options?

    I think a possibly better option (more module, use it when you need it) would be a helper component. It works like this: Add a custom component to the same GameObject as the SpawnPool component that only runs in the Editor and force-overrides whatever settings you want. This example is a simple implementation (untested code):
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using PathologicalGames;
    4.  
    5. [ExecuteInEditMode]                     // The component will run in the Editor
    6. [RequireComponent(typeof(SpawnPool))]   // Require so we don't have to test for it
    7. public class SpawnPoolGlobalOptionsOverride : MonoBehaviour
    8. {
    9.     public int preloadAmount = 0;
    10.  
    11.     private SpawnPool pool;
    12.  
    13. // Put it all in a preprocessor block so it is ignored when the game is playing or built
    14. #if UNITY_EDITOR
    15.     private void Awake()  // Runs when the component is added to the GameObject
    16.     {
    17.         this.pool = this.GetComponent<SpawnPool>();
    18.     }
    19.  
    20.     private void Update()  // Runs while the inspector is visible
    21.     {
    22.         foreach(PrefabPool prefabPool in SpawnPool.prefabPools.Values())
    23.         {
    24.             prefabPool.preloadAmount = this.preloadAmount;
    25.         }
    26.  
    27.     }
    28. #endif
    29. }
    You could add more settings of course.

    Implemented like this, the inspector shouldn't let you type anything in to the per-prefab options inspector (it will immediatly set the value back), which might be the best way to do it. An alternative would be to keep a private "last" field and in Update() only set the PrefabPool settings if the last field is different from the public field

    Please try this and let me know if it feels nice for your needs.

    By the way, this made me realize the docs needed an update for PrefabPools. All members are now shown here: http://docs.poolmanager.path-o-logical.com/code-reference/prefabpool
     
  45. tobicreaper

    tobicreaper

    Joined:
    Apr 30, 2013
    Posts:
    69
    Hi,
    I have a problem with pool manager. I integrated it fairly easily, but most of the time when I am playing the game, this is the error that I get:-

    (Clone)010 has already been despawned. You cannot despawn something more than once!

    Kindly tell me how to get rid of this.
     
  46. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    Hi,

    Please visit our forums and try the search feature. It may get you the fastest answer. Here is a search result page:
    http://support.path-o-logical.com/system/app/pages/customSearch?scope=cse-goog_1609549141&q=already+despawned


    If you still need information, please post to the forums or email support@path-o-logica.com.


    Cheers,
     
  47. mattSydney

    mattSydney

    Joined:
    Nov 10, 2011
    Posts:
    168
    Hi

    What is the best way of despawning nested game objects. For example I have a particle system that has other particles systems nested inside. I have added the parent to the pool but when I despawn it says that the child elements are not in the pool. Do I have to add them separately?

    Thanks
     
  48. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    Nested GameObjects or prefabs? You should be spawning prefabs and despawning using the same top object in the instance's hierarchy.

    Or do you mean you spawned two prefabs and then parented one instance inside the other instance's hierarchy?
     
  49. dreasgrech

    dreasgrech

    Joined:
    Feb 9, 2013
    Posts:
    193
    Can the PoolManager system handle pooling for non-Component classes (Plain Old CLR Objects) as well or does it only support GameObject pooling?
     
  50. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    Hi,

    PoolManager specializes in game object pooling, which is far more complex and deals with nuances of Unity's behavior and game performance. Pooling objects is much simpler and I've seen a number of great articles with copy-and-pastable solutions.

    Many people read simple code-object pooling articles (or have written pools themselves) think it will be easy to implement for game objects but I can assure you after 3 years of development that PoolManager probably saves everyone who uses it a couple hundred of hours of development and debugging over time. The API has grown deep but is still pretty simple to get going.

    I hope this helps!
     
unityunity