Global Save System – Part 1

For the past few days I’ve been struggling with one huge problem: persistence across levels. UDK may be an insanely powerful engine, but it lacks the ability to easily keep variables in memory between maps. Suppose I had a save state with data like the number of points a player has. The user would log in through the main menu, meaning that the save state (and thus the “points” variable) would be instantiated in UTEntryGame; however, once a deathmatch map is loaded UTEntryGame loses focus and we cannot reference the “points” variable, which has no instance in UTDeathmatch.

Thankfully, however, I made a breakthrough today. The key is to load the save state at the beginning of every level regardless of whether the player has logged in (UTEntryGame) or not (UTDeathmatch, UTTeamGame, etc.). This can be done via a function like so:

function bool LoadGame(optional string Username)
 local bool success;
 if(Username != "")
 success = savefile.LoadGame(Username);
 CurrentProfile = Username;
 success = savefile.LoadGame(CurrentProfile);
 return success;

If a username is specified, we load the game using that username, else we load it with the last loaded profile, CurrentProfile (which is a var config string). As you can see, as the player logs in through the main menu login screen, we pass something like LoadGame(“CliffyB”) to this function, which sets CurrentProfile = “CliffyB” and saves the config. When a map such as DM-Deck is loaded, this function is called but without a parameter, and so the CurrentProfile variable saved in UDKGame.ini is used instead.

It is a bit of a hack, but it works. The beauty of this system is that a theoretically infinite amount of profiles are supported, since each player profile is simply another .bin saved to Binaries\Win32.

As a side note, in order to reference the current game type from a child of GFxMoviePlayer, you would do:

local NetGame myGame;
myGame = NetGame(class'WorldInfo'.static.GetWorldInfo().Game);

Then the above function can be called by simply writing myGame.LoadGame(“username”). Easy, right?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s