playMaker

Author Topic: Changes to global variables are not saved when the game runs.[SOLVED]  (Read 1463 times)

qaaz345

  • Playmaker Newbie
  • *
  • Posts: 39
 Even if I saved the prefab!

I have a lot of problems with global variables in my project. Sometimes the global variable is renamed the same, or the global variable you changed at runtime to test the game could not be saved.

I never forgot to save the prefab.
« Last Edit: October 09, 2019, 02:29:07 AM by jeanfabre »

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Global variables are not related to prefabs. They are not local variables.
If you edit a local var in a prefab, it will be applied to all instances (assuming you have not tried to modify the same var in the instances).
A Global var does not work this way at all.

Global variables have a life of their own and I don't even recall being able to save as default values any new value you'd put into them at runtime. Once you stop the game, values are reset to the values defined in the Globals window.

For an analogy, imagine that Global vars are placed in an invisible prefab you cannot reach, but all you need to do to edit those values is to open a panel called Globals.
Every single time you use a Global var in a FSM, it acts like an instance of the one and true Global var that's centralized. In fact, it's just a reference that you use in your FSM.

It is very convenient since in the Global panel, you can actually check which FSMs are using it (right button after doing a refresh of the FSMs using it in the scene).

For names, it's even more tricky. At the moment, it is heavily discouraged to attempt changing the name of a Global var. Maybe in Playmaker 2 they will have changed this. So think wisely. Write your Globals' names differently than local variables so you can easily recognize them.
For example I begin a local var with smallcase and a Global with a capital letter.
(Maybe in the future Playmaker could use a slightly different background color to make the Globals stick out even more?)

Also, the only way you could change the name of a Global var locally would be to, first, detach said reference from its Global model.
In Variables tab, find the Global var present in your FSM at the bottom of the list and right-click on it: Make Local Variable.
It won't be a Global var any longer. It will be specific to this FSM.

You can also do without Globals entirely and simply dedicate a FSM to store variables which you read or edit/write remotely, from other FSMs, with actions like Get Fsm Int (Get/Set Fsm Int/Float/String/etc.).
But it will not allow you to know what FSMs remotely read or edit these variables.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Hi.
Just to add...

Changing thing during runtime not saving is a Unity limitation, not PlayMaker :)