playMaker

Author Topic: [SOLVED]Fix Prefab from loosing connection from in scene gameobject on spawn??  (Read 507 times)

nmillett

  • Playmaker Newbie
  • *
  • Posts: 8
    • View Profile
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.
« Last Edit: July 11, 2019, 05:09:19 AM by djaydino »

nmillett

  • Playmaker Newbie
  • *
  • Posts: 8
    • View Profile
Here is where I lose the link... on the FSM attached to the prefab that gets spawned.. How do I fix it?


nmillett

  • Playmaker Newbie
  • *
  • Posts: 8
    • View Profile
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.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4614
    • View Profile
    • jinxtergames
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.

9re9

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
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?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4614
    • View Profile
    • jinxtergames
Hi.
I can see that on the 'Set Fsm Game Object' your setup is wrong.

It should look something like this :


9re9

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
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?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4614
    • View Profile
    • jinxtergames
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



This should place the created object into the InputManagerFSM variable.

9re9

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
That worked! Thank you!