Saves

Hello,

I’ve tried today to get a save game system working, but when I tried it out, I found that my character always spawns at FVector::ZeroVector because it seems that the data isn’t written to or loaded from the disk properly. The transform seems to be okay in the “Save” method but inside the “Load” method the translation in the transform is 0.0f and the scale component defaults to 1.0f on each axis. This is my code:


void USavegameManager::Save(const FString& Save, const int UserIdx)
{
    if (UCustomSaveGame* SaveGameInstance = Cast<UCustomSaveGame>(UGameplayStatics::CreateSaveGameObject(UCustomSaveGame::StaticClass())))
    {
        SaveGameInstance->m_WorldName = g_MainHero->GetWorld()->GetFName();
        SaveGameInstance->m_HeroTransform = g_MainHero->GetTransform();

        if (!UGameplayStatics::SaveGameToSlot(SaveGameInstance, Save, UserIdx))
            GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Red, TEXT("UCustomSaveGame: Failed to save data!"));
    }
}
void USavegameManager::Load(const FString& Save, const int UserIdx)
{
    if (UGameplayStatics::DoesSaveGameExist(Save, UserIdx))
    {
        if (UCustomSaveGame* SaveGameInstance = Cast<UCustomSaveGame>(UGameplayStatics::LoadGameFromSlot(Save, UserIdx)))
        {
            if (g_MainHero)
            {
                g_MainHero->SetActorTransform(SaveGameInstance->m_HeroTransform);
            }
        }
    }
}
void USavegameManager::Delete(const FString& Save, const int UserIdx)
{
    if (UGameplayStatics::DoesSaveGameExist(Save, UserIdx))
        UGameplayStatics::DeleteGameInSlot(Save, UserIdx);
}

What could be the reason for this?

EDIT: I’m not reloading the level for now, so there’s no loading routine interfering.

Okay, it works now. For anyone having the same problem:
I just forgot to make each variable a UPROPERTY, so the serializer was unaware of the data.