Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: nmillett on March 12, 2019, 06:38:20 PM

Title: [SOLVED]Fix Prefab from loosing connection from in scene gameobject on spawn??
Post by: nmillett on March 12, 2019, 06:38:20 PM
Hey all,

I'm having a hard time figuring out a solution to what I am sure is a common occurrence.  I have a prefab that has an FSM game object attached to it.  When the prefab gets spawned into the scene I want it to activate a game object that always remains in the scene but its either is activated/deactivated.  From my experience, I have found prefabs only really stick to other prefabs and in scene objects like to stick to other objects but when trying to cross-connect the two the FSM on the prefab gets confused and loses the game specified game object.

I'm assuming there is a send event/ variable set up that solved this but was hoping someone on here can walk me through the fix.  Much appreciated.
Title: Re: Fix Prefab from loosing connection from in scene gameobject on spawn??
Post by: nmillett on March 12, 2019, 07:05:26 PM
Here is where I lose the link... on the FSM attached to the prefab that gets spawned.. How do I fix it?

Title: Re: Fix Prefab from loosing connection from in scene gameobject on spawn??
Post by: nmillett on March 12, 2019, 07:21:54 PM
Here is where I lose the link... on the FSM attached to the prefab that gets spawned... How do I fix it?

Changed it to broadcast all and made the variable global.  Did the trick.
Title: Re: Fix Prefab from loosing connection from in scene gameobject on spawn??
Post by: djaydino on March 13, 2019, 02:26:43 AM
Hi.
Its not a good way to use globals actually.
This post can help you a but understand what are the best practices :
https://hutonggames.fogbugz.com/default.asp?W1462


What you should do is :

When you spawn the prefab, store it in a variable (in create object there is a variable to store the object)

If you need the prefab to communicate to another object (for example the gameManager object) :
After spawning use 'Set Fsm Game Object' and you can set the "gameManager" object to the prefab. to a variable in the prefab.

Now you can use the variable to communicate with the "GameManager"

If you need another fsm to communicate with the prefab. you can also use 'Set Fsm Game Object' and set the Prefab to a variable in the desired gameObject/Fsm
or you can use 'Get Fsm Game Object' from that fsm and get it from the fsm that spawned the prefab.

With multiple prefabs you can also store them into arrays.
Title: Re: Fix Prefab from loosing connection from in scene gameobject on spawn??
Post by: 9re9 on July 08, 2019, 06:49:15 PM
Hi, I am doing the same thing and I'm not sure what you mean when you say:


...you can set the "gameManager" object to the prefab. to a variable in the prefab.


I have three game objects, each with a FSM:

1) InputManager: This game object has an FSM called InputManagerFSM. It receives keypresses and passes them to a player object FSM using Send Event.

2) PlayerObject: This game object has the player model and an FSM called Player Mover which receives events from the InputManagerFSM and transforms the player object in space.

3) Level Manager: This game object has an FSM called PlayerSpawner which instantiates the PlayerObject prefab and stores it as a local variable "PlayerObject".

Per your advice, I'm using "Set FSM Game Object" to have the player object receive events from the input manager. I've attached an image of how Level Manager FSM is set up. Can you advise what I am doing wrong?
Title: Re: Fix Prefab from loosing connection from in scene gameobject on spawn??
Post by: djaydino on July 08, 2019, 07:04:14 PM
Hi.
I can see that on the 'Set Fsm Game Object' your setup is wrong.

It should look something like this :

(https://i.imgur.com/eTzEQiy.png)
Title: Re: Fix Prefab from loosing connection from in scene gameobject on spawn??
Post by: 9re9 on July 09, 2019, 02:04:57 PM
Hi. Sorry I'm still not getting this.

What I'm hung up on is that I only have one variable, "PlayerObject" that was created with the Create Object action. So I don't know what other variable would populate the "Variable Name" field.

By "reference object", do you mean the instantiated prefab? If so, how does that differ from the "Game Object" field?
Title: Re: Fix Prefab from loosing connection from in scene gameobject on spawn??
Post by: djaydino on July 09, 2019, 04:32:59 PM
Hi.
Sorry i just noticed that you want the input manager to send events not the created object.

on the InputManagerFSM, create a variable (if you don't have one yet)
That name has to go in the 'Variable Name' and setup the rest, the same as on the image below

(https://i.imgur.com/olkV6Ta.png)

This should place the created object into the InputManagerFSM variable.
Title: Re: Fix Prefab from loosing connection from in scene gameobject on spawn??
Post by: 9re9 on July 09, 2019, 05:19:14 PM
That worked! Thank you!