How can I restart game and pass in game type and map name as params

This is for loading saved games, so I want to pass in the path of the file to load as well as which game type must be used. I want to do this via C++, not Blueprints.


#Config Vars

If you save a config var to disk before you do the map change, or you have a default binary file you always know the address of, you can save out the path of the file to load

//player controller class

then you can just run ConsoleCommand("open [mapname]"); after saving your info to disk.

then when your player controller runs its begin play, you can check if the config / binary file has valid data in it, and then ERASE that data (so that future loads do not think they are loading a save file)

That’s what I do anyways, works great for me :slight_smile:

#Config Wiki Tutorial

You can read/write to config files any time, without having to make any special UCLASS modifiers!

I’ve tested this!

A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums,Read%26_Write_to_Config_Files


Around 4.4 or so they are adding a persistent GameInstance class where you could store this kind of info, but it is not here yet


Hi Omnipresent Rama, thanks for the suggestions.

Using a console command to open the map has solved part of my question, however I’m not too fond of the writing and erasing config values for loading a game.

Compared to how this could be done in UE3, i.e. something like this:

ConsoleCommand("start "$newSavedGameData.MapName$"?Game="$newSavedGameData.GameInfoClassName$"?SavedGameToLoad="$newSaveGameUncPath);

it seems like a bit of a regression. I’ve also tried using InitGame, which does take options, but it doesn’t restart the actual game, or I cannot figure out how to pass options to InitGame and make it restart the level as well.

Also, for others reading this, you can call a console command in UE4 as follows:

FString consoleCommand = "Open " + GetWorld()->GetMapName();	

if (GEngine)
	GEngine->Exec(GetWorld(), *consoleCommand);