C++ SaveGame not working on packaged shipping build?

SaveGame works fine in PIE and when I launch it on my android device. When I package the game for shipping, save game is no longer saved to the phone. The file is never even created on my device. Anyone else experienced this or know what is going on?



void ABasic2DGameModeBase::LoadSaveGame()
{
    SaveGameInstance = Cast<UMySaveGame>(UGameplayStatics::LoadGameFromSlot(SaveSlotName, 0));
    if (!SaveGameInstance)
    {
        SaveGameInstance = Cast<UMySaveGame>(UGameplayStatics::CreateSaveGameObject(UMySaveGame::StaticClass()));
    }
}

void ABasic2DGameModeBase::SaveNewScore()
{
    LoadSaveGame();
    if (SaveGameInstance->SetScore(Steps))
    {
        UGameplayStatics::SaveGameToSlot(SaveGameInstance, SaveSlotName, 0);
    }
}




bool UMySaveGame::SetScore(int NewScore)
{
    if (NewScore > Score)
    {
        Score = NewScore;
        return true;
    }
    return false;
}


We use c++ savegame on android and it works fine.
I would not load the game every time you save a score value.
we leave the savegame just for data storage and all the functions on the gameinstance


// Fill out your copyright notice in the Description page of Project Settings.

#include "MySaveGame.h"

UMySaveGame::UMySaveGame()
{

    SaveSlotName = TEXT("PlayerSlot");
    UserIndex = 0;
    World05IsUnlock = false;
    LastLevel = FWorldLevel();
    FLevelsArray levelsArray;

    //son 5 mundos, creamos 5 sets de levels 1 mundo=6 levels
    worldArray.Init(FLevelsArray(), 5);
    FMapData mapData = FMapData();
    UE_LOG(LogTemp, Warning, TEXT("UMySaveGame called")  );

    for (int32 w = 0; w < 5; w++)
    {
        for (int32 l = 0; l < 6; l++)
        {



            if (l == 0)
            {
                mapData = FMapData(w, l, EMapState::UNLOCKED);

            }                
            else if (l == 5)
            {
                mapData =  FMapData(w, l, true) ;
             }
            else
            {
                mapData = FMapData(w, l);
            }



            worldArray[w].levels[l] = mapData;

        }
    }
}







void UMyGameInstance::Init()
{
    Super::Init();


    LoadGame();


}

void UMyGameInstance::SaveGame()
{
    if (saveGameRef == NULL)
    {
        saveGameRef = Cast<UMySaveGame>(UGameplayStatics::CreateSaveGameObject(UMySaveGame::StaticClass()));
    }

    UGameplayStatics::SaveGameToSlot(saveGameRef, saveGameRef->SaveSlotName, saveGameRef->UserIndex);



}

void UMyGameInstance::LoadGame()
{
    saveGameRef = Cast<UMySaveGame>(UGameplayStatics::LoadGameFromSlot(TEXT("PlayerSlot"), 0));
    if (saveGameRef == NULL)
    {
        SaveGame();
    }

}
//save info of current level
void UMyGameInstance::SaveUnlockWorld05()
{
    if (saveGameRef == NULL) return;

    saveGameRef->World05IsUnlock = true;
    SaveGame();
}
void UMyGameInstance::ChangeStateLastLevelPlayed(FWorldLevel _levelToUnlock)
{
    if (saveGameRef == NULL) return;
    int32 world = _levelToUnlock.world;
    int32 level = _levelToUnlock.Level;

    saveGameRef->worldArray[world].levels[level].mapState = EMapState::UNLOCKED;

}



@DonFrag I did that originally. After some time of playing the game I would get an access violation exception when saving the game. The SaveGameInstance becomes invalid. I’m not sure why but making sure it was loaded before saving corrected the issue. Screenshot attached.

Are you sure that slotname is initialized?
try to log both savegame instance and slotname before calling them.
Also try to to put the slotname directly

Yes, you can see see from the screenshot(bottom left) that SlotName is set to “PlayerSave” and SaveGameInstance is invalid.