playMaker

Author Topic: Passing FSM Managers between Scenes  (Read 2997 times)

mathius777

  • Playmaker Newbie
  • *
  • Posts: 38
Passing FSM Managers between Scenes
« on: June 02, 2013, 09:45:43 PM »
Hello. I went through the PM tutorials and they are pretty good, but I am curious about passing managers between scenes. The tutorials go over how to create a manager, etc, but how do you keep one instance of this manager for your ENTIRE game? I obviously don't want multiple input managers, especially if I am creating procedural levels(which I am).  And if I load a level and I use DontDestroyOnLoad on the manager, but return to the previous level, then there will be 2 managers in the scene.

I am just trying to understand the PM workflow for an entire game. How people pass their managers around, etc. Thank you.
« Last Edit: June 02, 2013, 10:13:50 PM by mathius777 »

mathius777

  • Playmaker Newbie
  • *
  • Posts: 38
Re: Passing FSM Managers between Scenes
« Reply #1 on: June 03, 2013, 01:00:32 AM »
Easiest way I have seen is to make prefabs of your managers(That contain FSMs),create global variables for each prefab manager, drag the prefab onto the global variable(of type game object) and have a Load object on each scene that calls Create GameObject and creates the prefab. This way each scene only needs one object that handles the loading of the managers for that level. It also prevents duplicate managers when you reload the same level.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Passing FSM Managers between Scenes
« Reply #2 on: June 03, 2013, 01:07:17 AM »
Hi,

 have you studied "dontdestroyOnLoad" feature? then you can have one gameObject that will survive any scene loading.

 The difficult is not really during the game itself, it's during editing, cause you likely want to access a particular scene on its own ( like levels), so you will need some logic to  check if you have your manager or not.

 so, each scene should have its own manager ( where it applies), and aFsm in that manager maintains a global flag ( a bool flag to know if it exists or not), if it exists already, then you destroy yourself, else, you set that flag to true.

Does that help?

bye,

Jean