10

Saving and Loading Data

Times when we wish to load data include retrieving high scores from previous plays of a game, or perhaps remembering data values between scenes. Another time to load data is when a level layout is stored in a data file (such as text characters, or a data format like XML or JSON), and when a scene begins, that data is loaded and used to dynamically create GameObjects for the scene. And of course, we must have saved the data previously in order to be able to load it at a later time.

Some of the saving/loading is ephemeral – just while a game is playing – and everything is reset the next time the game is run. Other times, data can be stored that is remembered between game plays, either as part of the build application’s ...

Get Unity Cookbook - Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.