Global object variables are not conserved between scenes

I followed the wiki: set the object as global. But if I change the variable of that object in scene1, go to scene2 the variable is not changed. Whether it’s a bug or something is missing in the wiki at the end it’s not working. So how to pass the variables?

Can we see your events? It could be as simple as a typo. Your variable names might not be exactly the same (capitalization must also match) or one might be global the other scene.

Edit: I didn’t notice the Global object part. I thought you it was just Global.

Global variables persist between scenes. Object variables, global or otherwise, only keep their default value between scenes if the variable was added in the object list.

When you create an object (global or otherwise) in the object list you are basically making a “template” for that object. What you create into the scene itself is an object instance. Instances only exist in that scene, and changes to their variables (via events or via clicking them within the scene itself) are for that specific instance. It doesn’t change the template itself.

1 Like

So how are we supposed to make object variables persist between scenes?
On a higher level, why is this explanation not in the wiki? are we supposed to all make the mistake, come ask for help here and realize our whole code has to be rewritten?

To clarify, you don’t make object variables persist between scenes, because they cannot. You would use global variables instead.

If you absolutely need an object variable, you could copy the instance variable value/string to a global variable, then copy it back to another instance once you’re in the new scene.

To learn about the different variable scopes, the Variables page has details: Variables - GDevelop documentation

To learn about object variables, the Object variables page has info, and explicitly calls out that they’re only for a specific instance of the object:
https://wiki.gdevelop.io/gdevelop5/all-features/variables/object-variables

To learn about global variables, the Global variables page has info, and explicitly calls out they’re useful for bringing data between any scene in the game: Global variables - GDevelop documentation

Overall, keep in mind that as I mentioned above objects in the object lists are just templates, so any instances you have in the scene don’t exist in other scenes. Global objects help you avoid having to recreate the Object in the object list (The template) over and over again if you’re going to use it in multiple scenes.

Creating an object instance in Scene 1, even using a Global Object, will not be the same instance as creating it in Scene 2. No scene variables will ever carry between scenes, and object instance variables are just object specific scene variables.

2 Likes

Maybe the information is there but it’s impossible to find it even after searching. I saw the wiki about making the object global and there was nothing else on this page. Probably there should be a consistent guide instead of a messy wiki. It would save you guys and us both a lot of time and pain.