Saving Actor Count not working

(Note: I don’t actually want the count saved, but rather meta data off each actor stored in an array, but this is just a simplified example of my issue)

So, the simplified use case, is I get all actors of a class and increment after each. Like so:

I’ve confirmed it will return the number 3, I’ve added a break point at the “Save Game to Slot” and confirmed it has 3 set, and that it saves successfully. If I reload that save (during the same runtime), it will return a 3. All as expected.

However, if stop the PIE and then restart, the save file will return a 0 (even when I debug the returned value right at “Load Game from Slot.”

What makes this confusing and frustrating, is that if I change the logic of the save to the below image, it will save and load the expected value (1 in this case), even when restarting the PIE.

For the life of me, I can’t figure out why this won’t save when it’s just a numeric value and the only difference being is how that number is populated.

Any help would be greatly appreciated

Can you show the code for saving and loading?

Top is saving performed in Game Instance

Middle is Build Save Game object just in case. This is what groups the data together and calls the function in question “World Status Save Data Get”)

Bottom is Load game function. You can see my print string where I’m checking the loaded value, and at this point on a new load, it has the wrong number)

(Sorry for the weird image, it would only let me upload one attachment I guess because I’m a new user so I just threw them all together in paint lol

Hopefully these are what you are wanting. I know it’s a bit weird and could probably be optimized a lot. It made sense in the beginning but as I’ve added new features and such it just turned into this nonsense lmao

1 Like

Thanks for this diagram, but I still have no idea what’s happening :melting_face:

What does ‘save data get’ take as input type? Object?

Also, if you’re having save game problems, don’t use async.

I would build it up slowly, rather than writing the whole thing and then trying to debug it :slight_smile:

I figured it out, and I could kiss you. After hours of still no progress and being unable to replicate this bug in a newly-made project, I went to lie down while mulling over everything, and your “don’t use async” text triggered some lost memory. I completely forgot that in my Game Instance, I added an “Event Shutdown” node that called my Save Game function a long time ago (I don’t remember why, lol), but a week or two ago, I had changed it to async, which is what triggered my memory that it even existed.

Anyway, this call to Save Game from the “Event Shutdown” was the culprit (async or not, it still caused this bug to occur). I never realized it was this as I would try to put breakpoints in my Save Game function, but they would never get hit on Shutdown (and from my testing, it appears to be impossible to debug any code run by the Event Shutdown).

My assumption is that by the time Event Shutdown is run, all the world actors are destroyed, so it would overwrite my first save with a new one without actors. I was then able to replicate it in my other test project, doing the same thing.

But after removing the call to Save Game in the Event Shutdown, my issue is now fixed. Thanks a million!

1 Like

:+1: :rofl:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.