playMaker

Author Topic: Send Variable to Prefab weirdness...  (Read 728 times)

curb47

  • Sr. Member
  • ****
  • Posts: 256
Send Variable to Prefab weirdness...
« on: October 01, 2020, 03:49:17 AM »
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.


« Last Edit: October 01, 2020, 04:11:39 AM by curb47 »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7622
    • jinxtergames
Re: Send Variable to Prefab weirdness...
« Reply #1 on: October 01, 2020, 05:16:43 AM »
Hi.
Try Setting the Set fsm Variable in a Next State.

or turn on sequence (right click empty space in action window to select)

Also use 'Set Fsm Game Object' instead of Variable.

Variable is to use with variable types that are not supported by default and might be slower.

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Send Variable to Prefab weirdness...
« Reply #2 on: October 01, 2020, 05:40:17 AM »
dino! Thank you so much!

After my really long wall of text, and thinking it was a big problem, and you solved it in a couple of short sentences.

You Sir, are a legend.

J.