Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: PalmlessPrayer on February 09, 2021, 02:51:43 PM

Title: Communicating between Prefabs and FSMs
Post by: PalmlessPrayer on February 09, 2021, 02:51:43 PM
After reading the best practices section of the site I still have some questions about the best way to transfer variables betweeen fsms and prefabs for the following scenarios

Scenario 1 - FSMs within the same Prefab.
So I noticed variables within a FSM within the same Prefab can't call each others variables without using a "Get FSM Bool/Int/Float... ". Wondering what the best practice for this is because isn't it possible to store the variables within the prefab itself.

Scenario 2 - FSMs to FSMs in other Prefabs
Assuming this is where I would use Global Events and pass gameobjects. For instance for my characters in a turn based game I would make a FSM which listens for a command event, this event will store what the command is and who it is for. Almosting like networking in away.

Really I'm just super interested to know the ways others are doing their architecture and communication between FSMs, Sub-FSMs and Prefabs.

thoughts much appriecated  : ) really enjoying PlayMaker so far
Title: Re: Communicating between Prefabs and FSMs
Post by: djaydino on February 09, 2021, 03:47:47 PM
Hi.
Scenario 1 : this is in all cases, not only on prefabs.
if you want data from a different fsm you need to use (Get/Set) Fsm Actions.
I'm not sure what you mean by 'store the variables within the prefab itself.'

Tip : There are several other custom Fsm actions on the Ecosystem (https://hutonggames.fogbugz.com/default.asp?W1181) like Fsm Bool Test / Fsm Float Operator for example.

Scenario 2 :
Global events is something different than global variables.
if you mean global variables, then it depends on the prefab.

in our game we only have a hand full of game objects set as global variables.
for example our character root / Meta Data / Item Data / Enemy Data.

inside those game objects, for example Enemy data, we have arrays with spawned enemies (prefabs)
which we add/remove on spawn/despawn.

Here are some videos that might be useful :



Title: Re: Communicating between Prefabs and FSMs
Post by: Alex Chouls on February 09, 2021, 04:13:09 PM
Variables are stored in each FSM. There are a few strategies for FSMs to share variables:
Some considerations for each approach:

Hope that makes some sense! They're all valid approaches, but it's good to understand their pros and cons.

There is also the related issue of referencing scene objects in Prefabs (https://hutonggames.fogbugz.com/f/page?W1707).
Title: Re: Communicating between Prefabs and FSMs
Post by: PalmlessPrayer on February 09, 2021, 04:23:09 PM
Thank you so much both of you, very detailed and useful.
Title: Re: Communicating between Prefabs and FSMs
Post by: PalmlessPrayer on February 10, 2021, 05:52:53 AM
I have some thoughts with communicating via events and I'm trying to implement the command pattern. Below is the first solution I've thought of so I bet theres probably a better way of doing it.

My current solution:
Prefab that runs commands has an FSM which manages received Command events.
Commands events recieved have already had their properties set elsewhere, for example a move command would have the command_name and move_pos.
The FSM that manages commands will store the command_name into a string array and move_pos into a vector 2 array within the FSM.
The prefab has a main FSM which has all the states such as move, attack and more. This main FSM listens for when the list of command_names array length is >0 then switches to a state based on the comman name, then grabs the relavent array data and deletes at index 0.

I have some concerns with this solution.
1. I'm using multiple arrays to store data for an event. Could I not store store an event in one array as a class?
2. How robust is listening for events? If my command listener FSM recieves an event while it is processing a command, won't it just disregard the current command and start over.

 

Title: Re: Communicating between Prefabs and FSMs
Post by: ch1ky3n on February 10, 2021, 11:06:49 AM

in our game we only have a hand full of game objects set as global variables.
for example our character root / Meta Data / Item Data / Enemy Data.


So make global of the object of the metadata that contains all the important variables?
gotta try this one!