playMaker

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

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 352
    • View Profile
Referecing a global manager[SOLVED]
« on: September 11, 2018, 02: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 13, 2018, 10:42:06 PM by djaydino »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4611
    • View Profile
    • jinxtergames
Re: Referecing a global manager
« Reply #1 on: September 11, 2018, 10:55:45 AM »
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: 352
    • View Profile
Re: Referecing a global manager
« Reply #2 on: September 12, 2018, 11:32:50 AM »
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: 4611
    • View Profile
    • jinxtergames
Re: Referecing a global manager
« Reply #3 on: September 12, 2018, 10:18:31 PM »
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: 352
    • View Profile
Re: Referecing a global manager
« Reply #4 on: September 13, 2018, 05:47:39 AM »
Thanks and I agree, I just was checking if that's the best approach.