Theoretically, global variables should be slower to access than object or scene variables. I don’t know if it is so in Gdevelop. Therefore, writing or reading into storage should cost the most resources in processing. Otherwise why wouldn’t most games with auto-save feature save data all the time?
It just depends on what you mean by “frequently”.
Games like Dark Souls are always autosaving, but it’s not constant
For example, the way dark souls handles it:
“Manual” save in the background any time:
- You finish interacting with an item
- You kill something
- Gain currency
- Open the menu/close the menu
- Opening a fog gate
- Teleporting
- After loading into an area, from anything
From my understanding, there is usually a roughly 5+ second gap between completing a save and when the next action can trigger a save.
“Recurring” save in the background roughly every time you:
- Move a certain distance in the same zone
It’s generally not on a timer (although some Souls game have an auto-save every 5 minutes), and by tying it into the actual actions that are happening can make it not happen repeatedly.
Silver explained you one part
But i see two others things when it comes to autosave
1 - As for performance
Frequent not frequent
Depends how much you read/write
I found that array with 2 values to check (X and Y coordinates)
Starts to lag for me around 50k JUST by checking them in game (not save load but condition check if X = child and Y = child var)
BUT that is in conjunction with some behavior that picks all objects each time
Basically this autotilling behavior
It connects adjacent tiles depending on from which side other tiles are to each of them
Where as you see you have around 200-300 on screen at a time
If add padding to it so i have around 1k tiles on scene while rest is in array
Then this number drops from 50k to around 30k
And that is when there is NO game there
No enemies no timers no timers no nothing
How it will drop if add these?
Hold space to spam tiles
And for example walk down
https://games.gdevelop-app.com/game-1dd460b5-84fb-4555-813a-d98e59a75b28/index.html
Now to illustrate issue i gonna enable minimap
Which is just shape painter and checking distance between player and tiles
Look how much tiles you can spawn now before getting fps lag
BTW if fps drops below 60 then fps counter turns red
https://games.gdevelop-app.com/game-f6557e13-a730-472c-8b88-313a7ddf917f/index.html
At around 40k tiles it starts to flicker for me even when standing still
Here i added padding of 64 so 2x size of my tiles since they are 16x16 in size
So you can’t see them create/delete on screen and it happens off screen
And my limit is around 30k tiles
https://games.gdevelop-app.com/game-62c74bdb-c176-4d51-94cb-26e95858cf6e/index.html
Imagine now i enable minimap and i add some game logic
You think i would get away with 10k tiles?
Cause i doubt that
But this is just my case scenario
There are various other cases where i would get better performance/numbers
For example right now all i cover EACH square of my map with tiles
What if grass tiles would not exist and be just green background?
How many tiles i would eliminate allowing me to have larger map without lag?
Well i still don’t have grass tiles but imagine if my world would be built from tiles like each square being separate tile
Even with grass trick numbers would be the same but map could be larger without lag
Since there would be less tiles on map
Other thing is my autotilling behavior which does lag like hell
If i could create chunk system this number would go up even further
Cause instead of checking if in each child X and Y match some cords
I would group whole chinks of map (areas) into child of child
Think of it as shoving in songs of artist to folders with their names
And now instead of searching for ONE song trough 10000 mp3 files
You would search 1st name of artist trough 200 folders
That is one aspect of why not autosave spam
Other is
A - autosave often defeat purpose of saving
You should decide when to save or if to save
Not game
Where in some games you only save what is unlocked
B - How many games you can think of that autosave would be essential?
Like seriously in something like dark souls i perfectly understand it
In something like GTA or Street Fighter
Kinda sorta soft autosave after mission/round/match
I get but not like each few secs
C - LAZYNESS
How many games you made?
Well don’t answer
But in how many you made or attempted to make
I can change controls?
How many have gamepad support?
How many have digital clock showing time?
How many have separate option to adjust game sound menu sound and music?
And we can go on and on
And lastly
D - When you have 2 save system in game
YOU as developer need to be very careful how you gonna manage them
NOT to let player mess up save his save with autosave
NOT to make it easy to overwrite older save with newer one from new autosave
Additional menu for allowing player to choose between autosave and manual save
I have few more ideas of why not to constantly auto save but i think i made enough of wall of text
And by now you should have general idea
I don’t know if this is classified as frequent, but I do have a weapon system which relies on picking up weapons and writing their information as a structure variable into a global variable. In the game, this will occur like a few times each minute.
Also, I tried making an inventory system, and every time an item is removed, all of the other storage locations must be reallocated to avoid disorder. There are about thirty slots in the inventory, and they will be accessed quite frequently in the game, so I’m α bit worried.
I agree with that I should optimize the storage system… but they don’t really cause any apparent lagging in the game, so I guess things are still ok. Anyway, I will try tidying up my code, and thanks for the advice!
I made a save system that stores information for hundreds of objects, and multiple properties for those objects (type, location, velocity, color, contained item) that fires every 2 seconds. I didn’t see an issue even when shortening the interval significantly.
I did do a couple of things to keep it efficient:
- Use the “open a storage” and “close a storage” actions properly
- Always write and read the data in the same order, so that property names don’t have to be evaluated (just know that position 1 is X, position 2 is Y, and so on)
- Convert entire data array to JSON to write it in one big chunk. (not sure if better for performance but definitely easier than writing your own events to loop through a million different storage locations)
I suppose the storages are automatically opened when they are written into or read from. I’ll try closing them sometimes. Thanks a lot!
Basically if you use read and write by itself, it is opening and closing the storage on each operation. Whereas if you open, do a bunch of stuff, then close, it is only opening and closing once.
can someone help me on my topic that I posted earlier. I really need help.