SaveGameObject arrays won't expand beyond the lenght of the first save.

Hi! My savesystem saves a custom struct into an array, for each user save. It works fine, BUT the first time I run the game, that decides how many items that array can take. If I play the game and only save 3 times, subsequent launches can only save to those 3 array indexes. If I spam save and push 20 items into the savegame array, I can save to those 20 indexes on subsequent runs. Why does it behave this way? I have searched, and I can find no description that this is how it should behave.

(edit: less compressed screenshot)

Image just for fun:

You have a logic error here

What happens to that new save game?..

You mean the “create new save game object”? it gets created if it doesn’t exists, but nothing more, since I don’t have anything to load from it. But the code below will reference it and stick data into it later during saving. If I’m mistaken, how should it be done?

1 Like

Ok, beg your pardon :slight_smile:

BTW, don’t use the async save, unless you know for sure only one thing is writing to the savegame at once.

I will look more at the code…

Can you show the code of ‘find updated slot’?

I think also using ADD might help instead of INSERT.

Because if ‘find updated slot’ is returning the wrong index, you won’t grow the array, whereas, ADD will always put a new slot on the end.

1 Like

gottcha, don’t use async save.
here’s that function:

here’s how I create the UI from them:

Here’s the UI:

I used INSERT because if I cleared a slot mid-array, then saved to it - it would be not found, and with ADD, that new save would appear last in the array. INSERT used the knowledge of which display index is has in the UI, and sticks it in there. WAIT!? you mean if I used INSERT at array index:(last index +1) it wont do anything? omg, that might be it!

You only need set and add :slight_smile:

add when you want to put it on the end, and set when you want to use a free slot.

insert is making the array bigger.

1 Like

SET would work, if I would keep empty slots in the array. Hmm, which I don’t. That’s an option!
But it really was INSERT that broke the code. Or rather my addition of an Autosave, causing new slots to appear at +2 of my array’s length. INSERT at +1 did work, but not +2… That explains why it worked the first run, but not on subsequent launches, since that first quit made an autosave :sweat_smile:. Hmm I could could chose either option now, one that clears away empty slots, and one that doesn’t… it will be donw to UX :thinking:
Thank YOU!!! This was quite the blocker to my system

1 Like

:+1: :smiley: