Oshigawa
Full Member
 
Posts: 228
Posts: 228
|
Post by Oshigawa on Sept 22, 2018 15:34:51 GMT
Hi,
i know this might be a bit out of scope. I started using nested prefabs with the latest beta and there's some trouble. so i'd like your advice on this one.
Before nested prefabs came, i made enemy squadrons as an object without children and then spawn the enemies as it's children (besause they also have their own children objects) and all behaved well, when they were destroyed, they despawned and got back to the pool.
But the work on those squadrons was tedious, i could not just drag and drop the ships and save the prefab, but i had to spawn them and then set their position by manually typing in the coordinates. In that regard, nested prefabs came as a blessing since i could visually make the squadrons and them simply save the prefab and spawn it.
But with that, a huge problem arises. When i spawn the squadron with enemies that are nested, enemies are not considered spawned, and therefore they can't be despawned. This is the message i get from the log: Game Object is already despawned. Will not despawn 'Provoker', but i don't get that it is despawned before that. Here's how it looks:
And here's how it looks with only the enemy, everything's fine:
With the message Pool Boss despawned 'Provoker' at 8.62 of course.
Plase advise.
|
|
Oshigawa
Full Member
 
Posts: 228
Posts: 228
|
Post by Oshigawa on Sept 22, 2018 15:48:41 GMT
Also, i don't quite get it, if they are not spawned, i guess they're instantiated?
|
|
|
Post by DarkTonic Dev on Sept 22, 2018 21:39:21 GMT
First, nothing will *ever* be Instantiated by Pool Boss except during startup, unless you have the for-testing-only setting turned on: "Auto-Add Missing Items", which is not for production code.
Now, regardless of how nested prefabs work (I haven't watched anything yet about Unity 2018.3), if you are spawning a huge composite prefab made up of other prefabs, and you are issuing a single PoolBoss.Spawn command, then just the one thing has spawned (the top-level one). Any subprefabs will not receive OnSpawned commands and are not considered spawned. In other words, if you have a Pool Boss item of a sub-prefab, it will not be used in that case.
If you want to use sub-prefabs and actually spawn them separately, they will use Pool Boss. You will most likely need to continue to separately spawn everything if you want to be able to despawn the sub-prefabs separately.
If you are using Core GameKit, you can use Triggered Spawners on the big prefab to automatically spawn the other children when it is spawned, and you can position those Triggered Spawners exactly where you want the sub-prefabs to appear. You'd just need to add a line of code to parent those to the parent prefab after spawning.
|
|
Oshigawa
Full Member
 
Posts: 228
Posts: 228
|
Post by Oshigawa on Sept 23, 2018 17:17:31 GMT
Sounds good, thanks for the advice!
|
|
|
Post by DarkTonic Dev on Sept 23, 2018 18:23:56 GMT
No problem.
|
|
lemmons
New Member
Posts: 16
Posts: 16
|
Post by lemmons on Dec 14, 2018 22:28:20 GMT
I'm trying separately spawning my child prefabs to no avail. I can despawn the parent but not the "children" even though they're spawned and tracked independently in Pool Boss. Here's a vid: pics.pco.bz/3f48a100885cand I'm using a visual scripting tool but you'll get the idea. This is the script I'm using to try and make this happen:  and here's a look into those Super Units just to be sure there's nothing wonky there either:   I know (I think I know?) it has to do with the parent/child relationship, but I've tried every possible combination of "Keep Parent" being on and off for all 3. And if you check the console output below, you get some weird information where it looks like the items Spawn themselves again right before they Despawn and then it says the parent is despawned before it actually happens? Please help shed some light on this, I'm sure it's user error. DarkTonic Dev please halp!
|
|
lemmons
New Member
Posts: 16
Posts: 16
|
Post by lemmons on Dec 15, 2018 1:32:38 GMT
Side note, I would love to be able to just spawn a prefab that has children to accomplish this same goal, so please let me know if that is possible but the whole reason I posted in this thread was because it sounds like it isn't. Instead of having Fire Basic spawn the two mini-fireballs, I would just make a prefab where Fire Basic already has the two mini-fireballs attached, but I tried for hours and couldn't make that work, especially when each mini-fireball needs to have its own collision detection for enemies.
|
|
|
Post by DarkTonic Dev on Dec 15, 2018 4:16:40 GMT
You can spawn a prefab with children (read the Composite Killables page on the documentation website), but once the children are destroyed they can never come back unless you write a script to fix killed things when it despawns. Unfortunately there's nothing in the Unity API that lets you "restore to prefab" and it's too complicated to code up to handle every script that could be on those sub game objects. If that's ok with you, just make enough clones of that prefab in Pool Boss so you don't ever re-use one.
I usually make it happen by using Triggered Spawners on a game object to spawn a few children with the Enabled Or OnSpawned event, then add a line of code in those to tell it how to parent to the other. But if somehow that parent prefab gets despawned with its children still intact, they'll still be there when it respawns next time. Which may be a problem, or not.
The other thing you can do is not actually parent the sub-game objects and just add a script that lets them follow the movement of the "parent" every frame. That way it won't run into any weird despawning issues like the other approaches and can be destroyed independently. In fact, I may put a thing like this on the roadmap to help that happen.
If you want to send me an example project that has the issues you mentioned, I will take a look and see if I can advise, but I can't really help troubleshoot without poking around in your setup and prefab construction.
|
|
lemmons
New Member
Posts: 16
Posts: 16
|
Post by lemmons on Dec 17, 2018 15:07:01 GMT
Interesting - yeah that's the problem I was running into, the parent houses two bullets that get fired and if one of the bullets collided and despawned but not the other one it was creating a lot of weird situations. The way I got around it was to still preload the parent and instead of despawning the child objects, I just disable off their sprite/animators and colliders and have them reenabled on awake. So far so good but I wanted to try and use OnSpawned and OnDespawned like you have in the Pool Boss docs. They don't act as triggers in Bolt (the visual scripting tool) meaning they can't start a chain like `Start` or `On Enable` can so even if it's hooked up to a listener it would still have to be part of a `Start` or `On Enable` chain which kind of defeats the purpose.
Anyway, it's working for now and I really appreciate your explanation!
|
|
|
Post by DarkTonic Dev on Dec 17, 2018 16:40:10 GMT
Awesome. Sounds cool!
|
|