|
Post by capitalj on May 3, 2014 7:36:41 GMT
Hi,
Just picked up the Core plugin and am trying out the pool boss component. Do I always have to call SpawnUtility.despawn to have an object properly despawned or can I just set the gameobject to inactive with the gameobject.setactive(false) ?
Also, I've run into the problem where there are not enough objects in the pool to spawn "... has no available clones left to Spawn in the Pool Boss." Shouldn't the pool boss in those cases take the next active object /spawned object and reuse it? I realize there is an option to allow more objects to be created, but in some cases of more trivial FX there is no need to have the effect actually spawn beyond the preset amount. In other pooling systems I've found that is what typically happens so that you will never have an error no matter what situation might come up in the game, and that if an object is not despawned properly, for whatever reason, you won't end up with an ever growing list of clones.
I also have a feature request: allow a parenting option, so that certain pooled objects could be assigned a parent when they are created. This is useful for NGUI type objects that belong inside the NGUI hierarchy. When I tried to use Pool Boss for an NGUI prefab the layer also changed from the NGUI layer to default for some reason, all other pooled objects seemed to retain their layer (could that be a bug).
Thanks! -JJ
|
|
|
Post by DarkTonic Dev on May 3, 2014 20:04:26 GMT
You should always call SpawnUtility.Despawn. If it's a Killable though, you can set it to automatically despawn when it goes offscreen, loses all hit points and a couple other triggers.
No, a pooling system should *never* reuse objects that are not disabled. That's not what they are for. I can change the message to a warning in the next version. If you have an ever-growing list of things not despawned properly, you need to fix that. We haven't seen that on our system yet.
Layers aren't automatically changed when you reparent things. I'm not sure exactly what you're suggesting for the reparenting thing. You can reparent them with code I believe.
|
|
|
Post by capitalj on May 4, 2014 20:11:30 GMT
Is there any way to modify the pooling code so that objects that are disabled are reused, so that Despawn doesn't have to be called? If you could point me in the direction of the code that handles that I'm sure I can figure it out. Well, never is subjective I guess, in some cases at least in my games it is useful to allow non-disabled/non-despawned objects to be reused. The every growing list just means in the event that I am not despawning them correctly (by mistake or design) and don't have the pool size limited, but in some cases I would rather have active objects reused than no objects at all. Anyways, that's just my feedback, no worries if it's not something that the system is designed for. Probably just an edge case  Hmm, that's odd about the layers. I'll try to record a screencap of this happening. Not sure if it's something I'm doing wrong but NGUI objects have their layers changed if they are spawned using Pool Boss, but not when using other pooling systems (making them unusable in NGUI). For now though I'll just avoid using pool boss for NGUI items, probably best to just instantiate those anyways  In terms of the parenting option, it would be nice to be able to set a parent during the creation of the pooled objects at the start of the scene. There are some cases where it is helpful to have certain pooled objects organized under a specific parent object (as in the NGUI case above). It's pretty minor though.
|
|
|
Post by DarkTonic Dev on May 4, 2014 21:17:47 GMT
If objects are disabled, that doesn't mean they are available in the pool. Those are 2 separate things. If you want that to happen, then go ahead and change your code that disables objects to instead despawn them.
The ever-growing pool object problem (if you have one) should be solved by figuring out why your prefabs aren't despawning correct, not by re-using active prefabs. If they are active and aren't supposed to be, I think you should fix the problem itself by figuring out how and when to despawn them instead of asking for a workaround. It will be best for your game.
I think you should still spawn NGUI stuff from Pool Boss. Instantiation is slow. Please send us a small project that reproduces that problem.
For re-parenting, you can put objects "already in the Scene" which in a way is reparenting. Also, after spawning an object, you can use script to assign a parent. That's normally how it's done if you need to do that. If you are saying that you should be able to assign a parent in the Inspector, and it will automatically reparent (no code to write), let me know and I'll add that to the Killable, Triggered Spawner and Syncro Spawner prefabs.
|
|
|
Post by capitalj on May 5, 2014 20:00:44 GMT
"It will be best for your game."
hmmm
|
|
|
Post by DarkTonic Dev on May 5, 2014 22:40:31 GMT
Yeah, I'm saying if you have a problem not being able to despawn everything that is supposed to despawn, you need to figure out why. Don't ignore the problem. If you find it's a bug in CGK, let us know. But we have had zero problems with the pooling system ourselves. We built it after a long time using Pool Manager.
|
|
|
Post by capitalj on May 5, 2014 23:56:52 GMT
No bug.
Let me ask another way. Is there a spot in the pool boss code where I could modify or derive from it to reuse active objects if it has run out of inactive/despawned objects? ie: the point at which it gives that error that it has run out of pooled objects.
|
|
|
Post by DarkTonic Dev on May 6, 2014 0:27:08 GMT
I don't understand why it would be a good idea to do that. Another problem if you wanted to insert code to do that: how would you decide which active object you should re-spawn? You could just be respawning the same item you just spawned 1 second ago, which would look really weird. Players would think it's a bug, I'm sure of it. Don't you think so?
Now you can just stick a TimedDespawner script on everything you spawn and have go back into the pool after X seconds, or other methods like that to despawn them. Why would you not use those?
|
|
|
Post by capitalj on May 6, 2014 2:48:27 GMT
So I guess that's a no?
Is there anyone else that might be able to point me in the right direction for the place to change the code?
|
|
|
Post by DarkTonic Dev on May 6, 2014 5:45:03 GMT
I'm not sure why you're not answering my questions in the last post - they are legitimate concerns and they make sense. I could look up the code and have you make a bunch of weird hacks, but I wanted to first make sure you wouldn't be alienating your game's users with strange buggy looking spawn behavior or "for no reason" neglecting to despawn items so that you can use them again (which is the normal way to use a pooling system). If you could answer any of that, I'd be glad to look up the code and you can go to town making it do what you like, if you still think it's necessary. However, I believe that all the tools you need are already there - you just need to use them. I'm not sure why you're trying to go around the system  .
|
|
|
Post by DarkTonic Dev on May 6, 2014 6:14:27 GMT
By the way, you can just double-click on the error that's logged ("... has no available clones left to Spawn in the Pool Boss."), and it will open up MonoBehavior and go to the exact line that logged that entry in the Console. Sometimes after MonoDevelop opens, you need to go back to Unity and double-click the error a second time and then it works. That would point you to the code if you want to try messing with it.
|
|
|
Post by Andy on Nov 25, 2014 16:57:14 GMT
I ran into something similar so I thought I'd write it down in case it helps anyone. I was adding some prefabs from a particle asset that I bought (ShurikenMagic if anyone cares). I also saw the "... has no available clones left to Spawn in the Pool Boss." message.
When I looked back at Core Gamekit example 3, I saw it was using a particle effect also (PlanetExplosion?) which called ParticleDespawn. But, when I added a Particle Despawn to the Shuriken prefab, it created a new particle effect at the top folder too. ShurikenMagic has its own sample script, DestroyObejctAfterSeconds, attached to the prefab. So, I replaced it with my own "Despawn particle from Core Gamekit" script and attached it to the particle prefab instead.
It's basically:
/// <summary> /// / /// </summary> internal void OnEnable() { this.StartCoroutine(this.Despawn()); }
/// <summary> /// Despawn the object after a period of time /// </summary> /// <returns>Yield instruction</returns> private IEnumerator Despawn() { yield return new WaitForSeconds(this.seconds); PoolBoss.Despawn(this.transform); }
|
|
|
Post by DarkTonic Dev on Nov 25, 2014 17:12:28 GMT
Good solution. When we used some cartoon particles from a package we bought, we needed to get rid of any "despawn / destroy" scripts that were on all levels of the ones we used. Then just add the Particle Despawner (or Timed Despawner) to the top-level of prefab. Then it's fine.
By the way, Timed Despawner is the same as what you wrote. You didn't need to code that.
|
|