Complete game restart via blueprints?

Is there a way to completely restart a game, equivalent to exiting the game and then restarting, via blueprints?

Not just restarting at the default level, but ending the game instance and starting a new one. Specifically, I have some code in my custom game instance constructor that needs to run.

Thanks,
Pagan

Hey pagancyc-

As long as the game is running it will still be considered the same instance. If you have code that needs to run more than once it would be best to move it somewhere other than the constructor. Then you can have it called by the constructor as well as call it wherever else you need to.

Cheers

Doug Wilson

Hi Doug, thanks for the quick reply.

Is there somewhere in particular you would recommend for the scenario detailed below? Or just create a function within the custom gameinstance and call it as needed?

Basically what I am doing is randomizing the map based on a seed that is saved using USaveGame. On startup, if the savegame exists, the seed is loaded and some values randomized. Otherwise, the seed is created, saved and then randomization is done. Those randomized values are then used in the PostInitializeComponents functions of some custom classes to change how (and whether) they appear.

I would like to have a menu option to restart (preferably via blueprints), which would delete the existing savegame, generate a new seed and a new map, and then start the player off fresh.

Thanks very much,
Pagan

The game instance is created as soon as the game begins to run. Assuming there is some sort of start menu, the game instance has already been created by the time you would get to it and will continue until the game is shut down (or the reset button is pressed on a console).

For what you’re trying to do it would be best to generate the seed when loading into the level. If the game is shut down and reopened the seed is still saved (via the method you described). Otherwise if Reset is chosen from the option menu you delete the seed at that point and return to the start menu (at which point a new seed will generate when you load into the level again).

In either case your best bet would be to create a function that is called when you begin “playing” the game rather than doing so in the game instance.

Got it working great now, thanks again for your help.