Variables, Global Variables, Object Variables?

Working on a game that features a system for keeping track of a small variety of current selections and health bars; the playable character has a health bar, they have a choice of costume, each costume has a damage bar (the damage of each costume is remembered even while another costume is currently being used), and a choice of three companions (each of whom also have health bars, costume choices, and costume damage bars to keep track of). The variables I’m using to keep track of all this information are currently kept under Object Variables. All the objects with variables are set to Global Objects.

I realized while working on the system that if the objects are deleted (or, in some cases, not created yet) the variables don’t get kept, so I’m gathering that Object Variables are only saved as long as the object exists, is that right? The workaround I figured out is to keep the objects around but mess with their opacity to make them invisible when not selected, which works, but my larger question is what happens if I change scenes? I want this information kept throughout the game, but will changing scenes delete the objects and clear the information saved in their Object Variables? What exactly does making an object a Global Object do?


The global object allow you to keep objects between scene, with default properties, in the objects panel. It help you avoiding to create again and again objects through different scene. Example : your playable character is composed of 3 objects, and all these 3 objects need to be present on each levels(scenes) of the game : making its global help you to keep properties defined (name of the object, behaviour added, object variables (default value)), etc.

When you create an object on the scene from the object panel, you create an “occurence”, and all related object’s variables below to this occurrence. When the scene is destroyed and the new one loads, all object occurence’s are destroyed, with their properties. Wich means an object, even global, will be reseted with object destruction/creation.

To do what do you explain here, you’ll need to pass objects variable’s values to global variables : global variables of the project are the only way to transmit information from one scene to another. In your case you can imagine structure global variable, with sub childrens :


Why don’t you use global variables directly?

ofc it’s possible, but it depends on how game mechanics works… only HarrisonGrey can judge what the best for his project.

Thank you guys so much, this information is very helpful. I’ll have to figure this one out soon, as I already have a lot of variables around.

FYI, the reason I went with Global Object Variables is because I didn’t know what I was doing. I saw there were Global Variables and then there were Global Object Variables, and I figured I’d put the variables I needed under the objects they apply to so I could reuse the names of them (there’s a “Health”, “CostumeSelect”, and “CostumeDamage” for each character). Turns out that was a bad idea because I didn’t know how Global Objects worked.