Hi,
Does anyone have an idea how to properly pass actor component variable to game instance and back so that I won’t get nullptr?
This is how I declare actor component variable in the first place in my Character class header, and as long as I don’t have to transition between levels it works quite fine:
UPROPERTY()
UEQHolder* playerEquipment;
And declaration in game instance subclass looks identically:
UPROPERTY()
UEQHolder* playerEquipment;
This is how I save it to game instance:
UDataKeeper* game = Cast<UDataKeeper>(GetGameInstance());
game->playerEquipment = playerEquipment;
However when I load it in my Character class BeginPlay, it returns nullptr:
UDataKeeper* game = Cast<UDataKeeper>(GetGameInstance());
if (game != nullptr)
{
if (game->wasInitialized)
{
playerEquipment = game->playerEquipment;
if (playerEquipment == nullptr)
{
UE_LOG(LogTemp, Warning, TEXT("Player equipment is nullptr!"));
}
}
}
else
{
UE_LOG(LogTemp, Error, TEXT("Game instance returned nullptr!"));
}
LogTemp: Warning: Player equipment is nullptr!
Just to be sure, I added checking if that pointer is null already at Saving to instance and it is indeed:
game->playerEquipment = playerEquipment;
if (game->playerEquipment == nullptr)
{
UE_LOG(LogTemp, Error, TEXT("Player equipment in saving to instance is nullptr!"));
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Player equipment in saving to instance is not null!"));
}
LogTemp: Error: Player equipment in saving to instance is nullptr!
Any ideas what am I doing wrong?