Hello there,
Okay, I did not see this coming.
Thanks to dino (again) I have my Prefabs set up nicely, with variables being sent to them upon Pooler spawn... all good so far.
But... I have this weird behaviour on one pooler spawned Prefab (Smart Bomb) that I can't wrap my head around:
In my little spaceship game, upon a certain trigger event a Smart Bomb prefab is created at the Mothership location that moves towards your player-spaceship for you to pick up:
When you pick up the Smart Bomb, the prefab is destroyed (Pooler Destroy Self), and you are now armed, locked and loaded, and can unleash massive destruction.
They player can hold a maximum of 3 Smart Bombs, so the Pooler Pool is set accordingly:
When the first Smart Bomb prefab is spawned (Prefab 1) , an object variable (player spaceship - ShipControl) is sent to it, to set it's Move Toward action:
Spawn Prefab 1.
Variable
received by Prefab 1.
All good so far, right?
The problem arises when the second (and third) Smart Bomb is spawned by the pooler spawn,
whilst Prefab 1 is still alive, ie before it has been picked up by the player and Pooler Destroyed itself. Basically, the object variable being sent to Prefab 2 and Prefab 3 is not being 'received'
whilst Prefab 1 is still alive.
Here's a screen-grab of the pooler spawn action for
Prefab 2, and it looks good. Apart form the spawn position, it looks like the object variable is being transmitted.
Spawned prefab 2:
Move Towards on Prefab 2 does not receive object variable:
I hope this makes sense so far.
I've done careful analysis of what's happening, and I've observed that when Prefab 1 of the Smart Bomb is picked up by the player ship, and destroys itself, the NEXT spawning of the Smart Bomb (also Prefab 1, reactivated) receives the object variable, however, if Prefab 1 has not been picked up by the player, and Prefab 2 and Prefab 3 are spawned, the object variable is not received by Prefab 2 and Prefab 3.
I don't understand what's happening. Even though pooled prefabs are clones, I thought they are treated as completely independent objects. I don't understand why Prefab 1 has to be destroyed before the sent variable works again, but only back on a newly spawned/enabled Prefab 1.
Maybe my understanding of what a pooled prefab is,
is wrong.
Please could somebody help me out here?
As ever, I'm extremely grateful for any advice and help.
Cheers,
J.