playMaker

Author Topic: GLOBAL G.O. VARIABLE CHANGES BETWEEN SCENE  (Read 6231 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: GLOBAL G.O. VARIABLE CHANGES BETWEEN SCENE
« Reply #15 on: February 27, 2014, 03:25:59 AM »
Hi,

 A global variable referencing a gameobject in a scene will loose that reference if this gameobject is destroyed ( deleted or because you changed scenes and that gameobject was not set to persists)

 A variable ( global or not) is only a "pointer" in the case of GameObject.


What you seem willing to achieve is called a "singleton". Something that can only be there once.

 Typically, you can solved this manually, by "finding" if a gameobject of the same name exists in the scene and destroy self if it does, or use a global variable "xxx" unique for each individual singleton, and check on START if that global variable is true, in which case it exists already and you destroy yourself, else, you set it to true and become that singleton.

Also, this is such a common pattern that I created an actino for this that handle this graceful in one action.

Typically, drop this action on a start state of a gamobject you only want once in your scene at any time. Use the reference as a unique identifier, and done.

If you have trouble understanding this, let me know. I'll provide a sample.


Bye,

 Jean