How do people design the save game feature in large/complex games?

1.10K views

The save game feature seems simple but it’s mind-blowing how it can return the exact state of a game with all elements/events organised in the correct order. Can anyone explain how it works?

In: 668

39 Answers

Anonymous 0 Comments

So it really depends on the game. However I can give you insight as a programmer.

Almost everything in a modern program is what is known as a class or object.

A class is a bit of code that acts as a container to make programming way more structured. An example of a class might define a vehicle in your game.

The class holds the properties of the vehicle:

Type, color, xyz position velocity and orientation.

It will also contain other properties, like the 3D model, textures, sounds e.t.c – but these are effectively defined by the type and color properties. Classes contain what is known as constructors (which have to be programmed in) – these take a minimal number of properties of the class, and they allow the class to construct itself into a fully featured representation. For example, you save the car’s type and color – when loading the game, the vehicle class’s constructor uses this information to go and fetch the correct 3D model and textures.

The class also holds all the methods – these are the things that the vehicle can do:

Drive forward, stop, turn e.t.c

The thing is these methods don’t need to be saved because they don’t change.

Classes can contain collections of classes (like the vehicle class might contain a class for each passenger).

To save this, you undertake a process called serialization. This recursively traverses your classes and saves the minimum information necessary to restore every class and every class they contain it back to their current state via all the constructor methods.

Nowadays, a lot of this can be handled for you via the game’s engine (Unity/unreal/source e.t.c)

Edit: It’s also worth pointing out that a lot of games don’t actually save the full state of the game, they just save an adequate set of information such that most people wouldn’t notice. For example, the game might save your player character fully, but only saves enemy position and health. When you reload the game, you might find the enemies do slightly different things since their velocity/orientation/AI state wasn’t saved. Since these things are highly dependent on player actions, and no human would generally do exactly the same thing upon reload – gameplay wise it may not be noticeable unless you’re looking for it.

Edit 2: If you design all your classes well to a set of rules, then the ability to save basically becomes an emergent property of your code, rather than something that you actually need to think about structuring and developing at the end.

You are viewing 1 out of 39 answers, click here to view all answers.