Scene Variables Vs Object Variables for temporary Large Structures

Hey everyone, just a technical question

Say I have 100+ variables like this one (The one inside EVENTS), with their own structures and additional info etc

From a performance perspective… is it better to save all of them as Scene Variables, or save all of them inside ONE object as Object Variables?

These variables are used only for special events that may or may not happen during your game run.
I don’t need them to exist in the scene all the time.

Will it make any serious difference in terms of performance? Or GDevelop does not care if they are scene or object variables?

From the engine debugger, I noticed that object variables don’t show up if you don’t have an instance of the object in the scene, so I suppose object variables are better for this kind of thing?

It might be interesting to create test event groups using both methods and then use the debugger’s profiler to measure things.

Unless there are are multiple objects, I would just use scene variables. The events are cleaner and easier to read/write. Especially, if you create formulas. Adding the variables to an object adds another step. The object would need to be accessed first instead of directly.

As for storage or memory. The variables would use resources whether there’s an object or not because a copy or template of the object is needed to create objects. It seems like this would double their needed space. Again, in the grand scheme of things, the amount is minimal.

It’s an interesting issue. I hope someone from gdevelop with knowledge of the internal functions responds. Otherwise, we’re just guessing and using our own personal preference.

If you’re just adding an object to use the object as a holder for the variables then the object itself would require extra resources in addition to the variables.

You are asking wrong question

Instead of which would be more performance friendly (scene vars)
Your questions should be how much you would gain

If i give you 9999999 $ or 9999999 $ + cents

We can 100% agree one is higher than other
But we can argue does it make any difference

Btw even more sense would have local vars

I think the biggest difference would depend on which method requires the most object selection conditions.

If it’s the same, it’d be the same performance. Whichever had more conditions for object selection would theoretically perform worse, even if its not a noticable impact.

Thank you for the replies, guys.

I guess it doesn’t really matter. Basically, I wanted to know whether variables that don’t exist in the scene yet (object variables) take up memory, but I guess things such as variables don’t affect the game performance that much. They do however affect the performance of the engine while you are working on the game.

I ran a test with over 200 large structures (Each with their own structures and content inside) without modifying them while the game was running, and I didn’t notice any big difference, only some lag at the beginning. Basically I created 2 scenes, one with only scene variables and one with only object variables that would show up once you create the object.

For now the only reason to use object variables is to not have to see this each time you try to type a variable that isn’t associated with the huge structure

Maybe the results will be different once you start modifying the variables during gameplay. I’ll need to experiment a bit more.

personal opinion:

I would use object variables, simply because they are more modular. If I need them in a scene, I can use them; otherwise, I don’t have to (but they’re still there… i know…).

Also, global and scene variables are fixed, while with object variables I can duplicate the object and change the values if needed.

About performance i don’t think is relevant but would be cool to test a structure of millions child to test the difference (in milliseconds)

Structures don’t display consistently in the autocomplete dropdown. It should only show the parent variable name in the list until you clicked on its name. Sort of like opening a folder or subdirectory. It works that way when use the variable as a value but not when you try to use it’s name to change its value.

I have wondered this before and I thought …why am I using object variables for the player?..this might be adding nanoseconds! Would be interesting to see a profiler test for a large repeat event using objects vars and then one using scene vars to see if there’s any difference