Hey guys,
So I’ve been working on a basic game for the Windows Platform lately, and I have a level transition system prototype roughed out, where it would Serialize player data to a binary file and load it back into the player character on level load.
Now I came across Ramas wiki tutorial: Game Instance, Custom Game Instance For Inter-Level Persistent Data Storage, not knowing of Game Instance. Now I’ve done a few successful tests with my own Game Instance class, with basic types such as FStrings and uint32. Obviously these values remain persistent on level changes, but I am wanting to work with UObjects, specifically a derived ACharacter class. Consider the following:
//Game Instance .h
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
AplayerCharacter * playerStorage;
//On Level Load in playerCharacter.cpp
UMainGameInstance * inst = Cast<UMainGameInstance>(GetGameInstance());
if(!inst)
{
//LogFunction
return;
}
inst->playerStorage = this;
Now assigning and testing playerStorage variables work in the scope that it was declared in, but if I try the following:
UMainGameInstance * inst = Cast<UMainGameInstance>(GetGameInstance());
if(!inst)
{
//LogFunction
return;
}
FString testString = inst->playerStorage->GetCustomName();
Will always toggle a breakpoint in Visual Studio(As I am debugging in DebugGame Editor). For some reason, and I don’t know why, inst->playerStorage is always NULL outside the scope when I assigned its value. Yet if I used say an actual FString, it will work.
This got me onto thinking, if there is no way to achieve this, would I be better off creating a structure with all the variables from my AplayerCharacter class and just use the structure in the game instance class?
Note* In small words, I am trying to store my player data for loading a level, then loading the player data back in, without saving to file.
Edit * Using structures accomplishes this, but with manually writing out all the variables. So I would like to know if I can store a copy of the AplayerCharacter in the game instance class, and have it work out of scope?
Thanks Guys,