playMaker

Author Topic: Global Variables  (Read 1073 times)

HedgeWizard

  • Playmaker Newbie
  • *
  • Posts: 15
Global Variables
« on: May 13, 2021, 06:57:01 AM »
Hi

I am aware that this subject has been addressed quite a few times already, but as someone who doesn't come from a background of coding I am struggling to understand the level of caution I should have towards using Global Variables. I understand that they are more fragile and prone to change, but I have trouble understanding how to avoid them to the extent that is being suggested.

In my project I am creating several managers to transfer data between scenes.

I read in Best Playmaker Practices (https://hutonggames.fogbugz.com/default.asp?W1462)that one should use max 2-3 global variables. What if I have 5 different system within the game that has to carry values between levels?

Is there any way to have say a Health System that does not make use of global variables and still carries values between scenes?

Thank you for your time.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Global Variables
« Reply #1 on: May 13, 2021, 07:34:59 AM »
Hi.

You can use a 'Dont Destroy on load'
this will make sure it does not get destroyed when the scene is changed.

also 'Singleton Manager' (Ecosystem) is very useful to make sure that you have only 1 version of that object.

So if you would load the scene again that has that object which you set with a 'Dont Destroy on load'

it will not load it again.