playMaker

Author Topic: Sharing INT between scenes without Global?  (Read 325 times)

daniellogin

  • Full Member
  • ***
  • Posts: 168
    • View Profile
Sharing INT between scenes without Global?
« on: July 12, 2019, 05:24:41 AM »
OK so I'm trying to avoid global INTS.

I have a menu in one scene where up to 4 different players can customise their avatar with 3 elements (hat, eye colour, body colour). The idea I had was simply to record each selection was an int so when their avatar loads, it simply uses each int to enable a hat / set a material.

Problem I just realised though is I don't know how to share this int between scenes without it being global. I had the idea that I would simply load the gameplay scene as Additive, have an FSM in my menu do a Set FSM Int to put the ints into the new scene, then unload the menu scene.

That doesn't work. I go back to see why and find all the Set FSM Ints red and empty in PlayMaker. Obviously not allowed to talk to FSM's in different scenes.

So what is a good way to handle this situation? Is my only option to have my costume int minding FSM in the gameplay scene identify itself as a Global Gameobject, then use that to do the Set FSM Int (since drag and drop is removes itself)?

Thore

  • Sr. Member
  • ****
  • Posts: 344
    • View Profile
Re: Sharing INT between scenes without Global?
« Reply #1 on: July 12, 2019, 03:56:45 PM »
I recall there are actions to store information into an xml or txt file, and load it from resource folder. I personally would store such things in scriptable objects, and write a custom action to load them into Playmaker.

You only need to write an easy script to generate custom scriptable objects with the values you want stored. Then you make one for each player, and two custom actions for playmaker to set and to get the values from there. It’s quite easy to do, but goes in part outside Playmaker.

daniellogin

  • Full Member
  • ***
  • Posts: 168
    • View Profile
Re: Sharing INT between scenes without Global?
« Reply #2 on: July 12, 2019, 08:15:18 PM »
I can't even program a 'hello world' message.

Unless there is a template I can copy and paste from, I'm stuck in the confines of PlayMaker.

I'm wondering though now about save files. The same sort of things used to save settings and even game data between playing it (not just scenes). Maybe I can use some save thing from the asset store + playmaker actions for it.

As it is, I need to wander into that territory one day anyway to save graphics settings and etc, so a user won't need to configure the game every time it's opened.

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 742
    • View Profile
Re: Sharing INT between scenes without Global?
« Reply #3 on: July 12, 2019, 10:58:46 PM »
For basic settings, you can save to playerprefs. This is a built in place to save (small) data. Its not a good place for real saves, as it can be hacked, but great for settings or less  important data.

For real saving, in playmaker, 'easy save' is by far the most popular save solution. You can find it on the asset store.

I have a video here about player prefs that starts you from 0:

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4615
    • View Profile
    • jinxtergames
Re: Sharing INT between scenes without Global?
« Reply #4 on: July 13, 2019, 05:20:07 AM »
Hi.
+1 For Easy Save.
I have been using it for years and tried several others (due to clients using other system/asset) and Easy Save Is by far the best one.

Quote
Problem I just realised though is I don't know how to share this int between scenes without it being global. I had the idea that I would simply load the gameplay scene as Additive, have an FSM in my menu do a Set FSM Int to put the ints into the new scene, then unload the menu scene.

That doesn't work. I go back to see why and find all the Set FSM Ints red and empty in PlayMaker. Obviously not allowed to talk to FSM's in different scenes.
You can communicate the other scenes a similar way as you would do with prefabs.

daniellogin

  • Full Member
  • ***
  • Posts: 168
    • View Profile
Re: Sharing INT between scenes without Global?
« Reply #5 on: July 13, 2019, 09:35:40 AM »
For basic settings, you can save to playerprefs. This is a built in place to save (small) data. Its not a good place for real saves, as it can be hacked, but great for settings or less  important data.

For real saving, in playmaker, 'easy save' is by far the most popular save solution. You can find it on the asset store.

I have a video here about player prefs that starts you from 0:

Thank you. I'll check out the prefs, and yeah if I go that route, I have heard of Easy Save... maybe I have it already. Either that or it's in my favorites (watch) list.


Thore

  • Sr. Member
  • ****
  • Posts: 344
    • View Profile
Re: Sharing INT between scenes without Global?
« Reply #6 on: July 13, 2019, 09:42:03 AM »
I've decided to take your plight as an incentive to write up a guide for scriptable objects, because they're incredibly useful. You'll find that here:

https://hutonggames.com/playmakerforum/index.php?topic=20829.0

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14698
  • Official Playmaker Support
    • View Profile
Re: Sharing INT between scenes without Global?
« Reply #7 on: July 16, 2019, 01:29:49 AM »
hi,

 you can also use dont destroy on load, which will make your gameobject survive the scene loading, and so objects in the new scene can look for it, or the actual object and send a global event when scene is loaded to say hello and have other fsm catch that event and get infos from the event sender.

 Bye,

 Jean