Home Game Development Saving And Loading Game Data With Blueprints And C++ In Unreal Engine

Saving And Loading Game Data With Blueprints And C++ In Unreal Engine

0
Saving And Loading Game Data With Blueprints And C++ In Unreal Engine

[ad_1]

				
					#embody "GameInstance_CPP.h"
#embody "SaveGame_CPP.h"
#embody "Engine.h"

void UGameInstance_CPP::Init()
{
	// examine if there may be recreation knowledge to load it
	// or create a brand new one if the sport is simply beginning
	GameData = Cast<usavegame_cpp>(UGameplayStatics::LoadGameFromSlot(SaveSlot, 0));

	if(!GameData)
	{
		// create a brand new recreation knowledge
		GameData = Cast<usavegame_cpp>(UGameplayStatics::
			CreateSaveGameObject(USaveGame_CPP::StaticClass()));

		GameData-&gt;PlayerLocation = FVector(0, 0, 0);
		GameData-&gt;Score = 0;

		UGameplayStatics::SaveGameToSlot(GameData, SaveSlot, 0);
	}

}

void UGameInstance_CPP::SaveGameData(FVector PlayerLocation, int32 Score)
{
	if (GameData)
	{
		GameData-&gt;PlayerLocation = PlayerLocation;
		GameData-&gt;Score = Score;

		UGameplayStatics::SaveGameToSlot(GameData, SaveSlot, 0);
	}
}

USaveGame_CPP* UGameInstance_CPP::LoadGameData()
{
	if (GameData)
		return GameData;
	else
		return nullptr;
}</usavegame_cpp></usavegame_cpp>
			

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here