Hi there, I’m relatively new to UE (2 years more or less) and I’m currently in a team working on a project. I deal with all the UI visuals and scripting + additional ones, and right now I’m working on a save/load system with multiple slots that the player can create with a custom entered name.
Usually I manage to come up to a solution on my own, but this time it’s really driving me nuts. I get a specific, weird bug from saving and loading that I really don’t understand. I tried almost everything it could come up to my mind as the possible culprit, but nothing seemed to work and I can’t seem to find the answer anywhere online.
The system I’ve built uses two savegame objects created at the start of the game in the game instance with a isvalid? Check
One savegame object is to store all play data (like character stats, inventory, level name) and the other to store video and audio settings along with slots parameters like entered name, if the slot is read only and can be used to load, and screenshot taken from a scenecapture2D attached to character’s main camera.
As for the slots system, I have 4 max placed on a grid, not accessible until first slot is taken and first save is done.
I have two setups in the main menu: new game and load game. When the player choses new game, custom text can be entered and, when committed, is stored in the savegame object and assigned to the first available game slot.
The four slots are instances of another SaveSlot widget which also stores several editable variables such as slot number, slot text, a boolean to tell if the slot has been used and so if has to be loadable or not, screenshot brush and visibility, and so on.
Individual slot save and load logic are handled by custom events in the SaveSlot widget itself with reference to the slot number when pressed.
Each time I save or load to/from a slot, the slot number is also set to a int variable in the game instance, so that I can later use it from within the character controller (where main save and load functions are) to save and load game to that same slot number, always combined with an append and string as the main slot name.
Save and load functions have both a sequencer that gets the data from the variables on the savegame object and sets them again to character, controller and inventory variables, and viceversa.
Now, save and load between levels work fine as intended, and so it seemed for the save and load from slots, cause actually I don’t get anything unusual/strange from all the print string I’ve placed, it saves and loads to and from the right slot, at least until I found out two problems:
- If I save on more than one slot, choose to load one first then a second one and save, when I come back to the previous one, all the variables have been overwritten with the others, both slot entered name, character variables, and so on.
- If I end play in editor and restart, saves are still there, but loading messes something up the first time and then deletes all saved variables on the second time I load that slot.
What I’ve tried:
- Changing the logic to place the slot dynamically on the grid with a “for each loop“ and “add child”, also clearing and refreshing the slots array on event construct each time, just for safety.
- Creating the savegame objects each time a save has to be done, and not only once in the game instance
- Using a single savegame object instead of having two
- Using the manual slot loading when pressed instead of automatically get the slot number and set it
- Not using the sequencer in the save/load functions in the controller bp
- Using the async save and load from slot, instead of the sync one
- Using the “does save game exist” instead of the isvalid? node in the game instance
Nothing worked, same problem, still can’t find out what the reason is.
What am I doing wrong, or am I missing something? I’m currently using version 4.25.4
Thanks in advance.