Download

New Wiki, Using Game Instance Class for Inter-Level Persistent Data

Dear Community,

I have just published new tutorial on how to use the new Engine feature called the Game Instance class!

This is only in the engine as of 4.4, but it is very powerful!

You can use the Game Instance class to store data between level transitions!

So where previously you might have had to save stuff out to config file or use a save object, or write out to binary file, now you can carry data from one level to another using the Game Instance class!

In the example code on the wiki I show you how to count the total number of ticks that have elapsed since your game application window first opens and the first level is loaded! The count keeps rising even after changing levels multiple times!

You can now store any data you want between levels!

Epic Wiki Link


**Sample Code From Wiki**

Here's the code where I am using a custom Game Instance class to count the number of total ticks that occur in the PC, even across different levels!



```


void ASolusPC::PlayerTick(float DeltaTime)
{
	Super::PlayerTick(DeltaTime);
	
	USolusGameInstance* SGI = Cast<USolusGameInstance>(GetGameInstance());
	if(SGI)
	{ 
		SGI->InterLevelPersistentValue++;
		VShow("Inter level value is now!", SGI->InterLevelPersistentValue);
	}
	
}


```



Essential Tip

To use a custom Game Instance you need to set your DefaultEngine config file!



[/Script/EngineSettings.GameMapsSettings]
GameInstanceClass=/Script/Solus.SolusGameInstance


Enjoy!

Rama

Yes it really is that easy!

Game Instance is great fun!

Thanks Epic!

Rama

Yes it is, I am using a Game Instance for all my persistent data serialization. Serializing the state of all objects between levels. Allowing the world to appear persistent. A lot of fun.

Woohoo!

Great to hear from you Ehamloptiran!

:slight_smile:

Rama

Great job Rama ! :smiley:

Really helpful. I was searching for something like this since last few days but got nothing https://forums.unrealengine.com/showthread.php?47676-Chaning-map(game-mode)-are-the-values-saved.

And this is really simple too…

Nice one! With this one and the GameSingleton (through the GameSingletonClassName config value) we have a lot of freedom regarding persistent instances.

Thank you Rama! :smiley:

Haha thanks MrNexy, great to hear from you!

:slight_smile:

Hee hee! Glad you like!

Very nice to hear from you Moss! Yea UE4 C++ is so much fun!

You’re welcome!

:heart:

Rama

Thanks dude! Yeah ditching UnrealScript was the best decision ever made :smiley: I have been using UE3 for about 8 years and I also tended to implement stuff in native then script, you just get more from the engine.

Yea I’ve been enjoying your community contributions / general presence!

I can’t wait to see what you come up with in UE4 with full C++ access!

Make sure to let me know when you publish your amazing creations!

Rama

I have some plugins in the works :smiley:

Bumping this for anyone who is not yet familiar with the wonderfulness that is Game Instance class!

Rama

is there a way to get 2 game instances cause i got one bp and on in c++