playMaker

Author Topic: Have FSM present in all scenes[SOLVED]  (Read 1904 times)

playsteven

  • Junior Playmaker
  • **
  • Posts: 75
Have FSM present in all scenes[SOLVED]
« on: November 08, 2017, 04:19:59 AM »
Hi,

I want to have a couple of FSMs which will be present in all my scenes to deal with ads and billing, etc.

What's the easiest way to do this?

Would I put an object in the first scene (which is little more than a loading screen) and mark it as do not destroy?

If I did that, how would I access/reference the FSM from FSMs in other scenes?

Thanks,
Steven
« Last Edit: November 09, 2017, 01:53:23 AM by jeanfabre »

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Have FSM present in all scenes
« Reply #1 on: November 08, 2017, 04:29:18 AM »
Very interesting question, i'm interested in this too!
Available for Playmaker work

playsteven

  • Junior Playmaker
  • **
  • Posts: 75
Re: Have FSM present in all scenes
« Reply #2 on: November 08, 2017, 06:16:30 AM »
I think I may be making progress...

In scene one I've created an object with an FSM using the action Do Not Destroy, so this object appears in other scenes. In this FSM I can add some Global Transitions.

In other scenes I can use Send Event and Broadcast All to use the Global Transitions in the (not destroyed) object which now appears in all scenes.

Is this the best way?

Now I just have to work out how to Get FSM Int values from the object in the other scene. Or can I only use global variables?

Gustav

  • Junior Playmaker
  • **
  • Posts: 53
Re: Have FSM present in all scenes
« Reply #3 on: November 08, 2017, 08:14:18 AM »
Hi,

what you are looking for is called a Singleton.

Jean made a custom action to help achieve this behavior. It's available on the Ecosystem.
This topic might also be helpful.

Just make a Prefab out of the object which contains the FSMs and place it in all scenes you want to use it. If you want to reference it from other FSMs, search for the object (e.g. by tag) the FSM is sitting on and get the FSM. This FSM should call on start the action Singleton Manager with its own unique reference. So if you load an new scene this Prefab checks if there is an object with the same reference and if so it destroys itself. So only the object that already exists in the scene (from the last scene) will remain in the scene.

playsteven

  • Junior Playmaker
  • **
  • Posts: 75
Re: Have FSM present in all scenes
« Reply #4 on: November 08, 2017, 08:23:43 AM »
Thanks Gustav, perfect :)