Hi Everyone,
I made a Savegame Object with a Variable TMap<AActor*, bool> Doors. So I basically want to save if the Door was opened or not already.
I have Main Menu where I can choose a Save Slot and start the game. The on clicked event of the Main Menu Loads the Savegame Object and therefore also the TMap. Then I open the level and set the actors data from the savegame.
In the Level Blueprint in BeginPlay() I have the following code:
TArray<AActor*> OutDoors;
Doors = Cast<UMyGameInstance>(GetGameInstance())->SaveGameData->Doors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), ADoor::StaticClass(), OutDoors);
for (AActor* OutDoor : OutDoors)
{
TArray<ADoor*> KeyDoors;
Doors.GetKeys(KeyDoors);
ADoor* CastDoor = Cast<ADoor>(OutDoor);
if (CastDoor)
{
if (Doors.Find(CastDoor))
{
CastDoor->IsOpen = *Doors.Find(Cast<ADoor>(OutDoor));
CastDoor->UpdateDoorLocation();
}
}
}
The Problem is on the place with (Doors.Find(CastDoor)) line. It seems that the Doors at this point only contains nullpointers.
That leads me to my first Question:
What is actually saved here? Because if I save a pointer, it just would be a memory adress right? Or is the Object serialized in some way automatically?
The second thing, that confuses me is, if I load the Savegame again in the Level Blueprint in the first line of BeginPlay() like this:
UMyGameInstance* GameInst = Cast<UMyGameInstance>(GetGameInstance());
GameInst->LoadGame(GameInst->SaveSlotName);
Then the Doors.Find actually has a Result and everything works fine. Why is that?
Thanks for the answers.