When I load a game actor location is not set

I have a game where the player can load their save file from any level, including a start menu. In my code I call UGameplayStatics::OpenLevel and pass in my saved level name. Then I set my characters info. Finally I set the location and rotation of the actor based on the saved game data.
I think the problem is that when the level is loaded all that data is cleared out because the level opens at where I have the player start actor and the location and rotation i set are zeroed out.

When I call my load game function the data I load from the slot exists and is what I should expect

Here is my save and load game functions:

void AMeatCharacter::SaveGame()
	UMeatSaveGame* SaveGame = Cast<UMeatSaveGame>(UGameplayStatics::CreateSaveGameObject(UMeatSaveGame::StaticClass()));
		SaveGame->PlayerStats.MaxHealth = PlayerStats.MaxHealth;
		SaveGame->PlayerStats.Health = PlayerStats.Health;
		SaveGame->PlayerStats.MaxStamina = PlayerStats.MaxStamina;
		SaveGame->PlayerStats.Stamina = PlayerStats.Stamina;

		SaveGame->Rotation = GetActorRotation();
		SaveGame->Location = GetActorLocation();

		FString LevelName = GetWorld()->GetMapName();
		SaveGame->LevelName = LevelName;
		UGameplayStatics::SaveGameToSlot(SaveGame, SaveGame->SlotName, 0);

void AMeatCharacter::LoadGame()
	// This is fine for now however, this is going to be problematic when the need for saving levels will be necessary
	UMeatSaveGame* LoadGame = Cast<UMeatSaveGame>(UGameplayStatics::CreateSaveGameObject(UMeatSaveGame::StaticClass()));
	LoadGame = Cast<UMeatSaveGame>(UGameplayStatics::LoadGameFromSlot(LoadGame->SlotName, LoadGame->SlotIndex));
	if (LoadGame)
		UGameplayStatics::OpenLevel(GetWorld(), *LoadGame->LevelName);
			FInputModeGameOnly Input;
		PlayerStats = LoadGame->PlayerStats;

Hey vycanis1801,

take a look at this

That should put you on the right path. Also, are you saving the rotation and location as an FVector? Try casting your character’s location to game instance and save it there. Then grab it from there upon loading your level. Game Instance is persistent in regards to data, unlike your character class.

Yeah If you look at the save game function you should be able to see that I’m using GetActorRotation and GetActorLocation and writing them to the variables in my UMeatSaveGame object.

My problem is that when I call open level from GameplayStatics it reconstructs my character object which deletes the data I just tried to load.

I noticed you mentioned casting to a game instance? I’m not too familiar with that class. I’ll do some research into how I can use that

Okay so I added a game instance class and it’s still not setting the saved location when I call open level

Okay so I did some blue print scripting with game instance, game save, and level blueprint classes. At the very basic level I set a Boolean variable when I “load” a game. After loading the level I check the game instance to see if that value is true. If so, that means it begin play was triggered by my load event. Then, I call a different load function from my character controller that loads the slot again. This time, getting the save location and rotation. And finally, I get the player character and set the rotation and location.

Now, this solution means that I am calling LoadFromSlot twice in order to load the game. Does anyone know if there is a more elegant and or optimal way to do this. I can provide any pictures if clarification is needed.

If I don’t hear anything else I’ll post a youtube link that is a tutorial of how I came up with my solution. Hopefully in both blueprints and c++.