playMaker

Author Topic: Referecing a global manager[SOLVED]  (Read 1414 times)

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Referecing a global manager[SOLVED]
« on: September 11, 2018, 05:18:46 AM »
I am currently tidying up my game logic and made a few mistakes in using global variables to handle logic. I want to come away from using global variables and have one FSM manage all of this. Ive been looking into using something like a singleton. Now all that I'm struggling with is the best approach to reference this singleton. Lets call it 'manager'. Its more complex as most of my objects are prefabs, so no way of using parenting as an alternative .

The only option that I have read about is (https://www.youtube.com/watch?v=u4PV78MB2xE)...

1. Use a global variable to store a reference to the 'manager'.

but don't really want to use a global variable as this defeats the object. I don't want to use broadcast etc to the performance impact.

Is there another option for this?

Nick
« Last Edit: September 14, 2018, 01:42:06 AM by djaydino »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Referecing a global manager
« Reply #1 on: September 11, 2018, 01:55:45 PM »
Hi.
For prefabs, the best solution is a global

I don't use globals for anything else.
Sometimes i have 2 or 3 globals to reference GameManager / DataManager / Other Manager.

If the prefabs are created (or Pooled) @ runtime you could have a variable on them (called GameManger" and set the GameManager object on the created prefab variable.

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Re: Referecing a global manager
« Reply #2 on: September 12, 2018, 02:32:50 PM »
Hi

Ok well I guess I'll stick with using this approach. I thought there might of been a better alternative. I heard that globals are easy to hack, so was trying to think of another option. But I guess i'll just have to put in a check for this before the game launches.

Nick

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Referecing a global manager
« Reply #3 on: September 13, 2018, 01:18:31 AM »
Hi,
They can hack and maybe change the game object
but that would break the whole game.
so it would be useless.

Other data are prone to hackers.
Like putting score/coins/gems/items data in the globals.

So it is save to use it to reference the game objects :)

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Re: Referecing a global manager
« Reply #4 on: September 13, 2018, 08:47:39 AM »
Thanks and I agree, I just was checking if that's the best approach.