Playmaker Forum

Playmaker Help & Tips => Playmaker Help => Topic started by: playsteven on November 08, 2017, 02:19:59 AM

Title: Have FSM present in all scenes[SOLVED]
Post by: playsteven on November 08, 2017, 02: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
Title: Re: Have FSM present in all scenes
Post by: krmko on November 08, 2017, 02:29:18 AM
Very interesting question, i'm interested in this too!
Title: Re: Have FSM present in all scenes
Post by: playsteven on November 08, 2017, 04: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?
Title: Re: Have FSM present in all scenes
Post by: Gustav on November 08, 2017, 06:14:18 AM
Hi,

what you are looking for is called a Singleton.

Jean made a custom action (http://hutonggames.com/playmakerforum/index.php?topic=13160.msg61375#msg61375) to help achieve this behavior. It's available on the Ecosystem.
This topic (http://hutonggames.com/playmakerforum/index.php?topic=14464) 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.
Title: Re: Have FSM present in all scenes
Post by: playsteven on November 08, 2017, 06:23:43 AM
Thanks Gustav, perfect :)