where are you holding referance of your saved game data? GameInstance ?
Actually the thing is careful if you are calling reference not the copy itself.
Ok what you can do is, think save game as just a UObject, means only saves saved game data. For the save and load you can use GameInstance class. Dont put any additional function inside of savegame class.
when you need variables you will call them from referance that GameInstance holds. Otherwise its inevitible to have such issues. GameMode will control your scores and saves with the help of GameInstance. I hope I can shape design on your mind.
So i should create a gameinstance holding a reference to a savegame in the gamemode? I can try but i dont see how it would change the behavior. I tried debugging and the created savegame in the save function has the correct values, only loading changes it and i dont see how.
As I understand what you try to achieve is as a design :
GameInstance
Create a GameInstance in cpp and have reference to your save game TitlesSaveGame, and have functions like
UPROPERTY(BlueprintReadOnly, Category = "Save Game")
class TitlesSaveGame* InstancedGameData;
// save game you can call with variables to be saved. Depends on your design.
UFUNCTION(BlueprintCallable, Category = "Save Game")
void SaveGame();
// here you can load your game.
void InitSaveGameSlot();
// These both functions are build in in game instance, UE will call them whenever game starts. Basically you can load your game in this function
void Init() override;
// Called by the game as it shuts down.
void Shutdown() override;
GameInstance is accessible from anywhere that you can call above functions to maintain your save/load game logic.
How to call game instance is
UGameInstance* GameInstance = Cast<UGameInstance>(UGameplayStatics::GetGameInstance(this));
// And later you can call your function like follows
if (GameInstance) // always check
{
GameInstance->SaveGame();
}
Works. Added an int to the savegame, serialized it to 9, incremented it in the save function and it loaded correctly as 10. Its just the struct that kepps on not loading.
youre welcome Most probably you save copy of your struct not the itself. Its better to have in this way. Your game will get complicated in coding overtime. Keeping clear in the beginning will always help you later.
Maybe creating a savegame more than once makes smt weird? I dont know.
EDIT: IMPORTANT: It did not work! It just saved in one session, when restarting the engine, the same error occurs. The Solution : DONT SAVE TWO SAVEGAMES ON THE SAME SLOT, EVEN IF THE NAME IS DIFFERENT. WHY? WhY Was I looking for this forever?