Persistence
Data persistence in a realm refers to the ability of data to remain intact and accessible even after the game server stops working or shuts down. You can achieve this data persistence with the Realms service and Unity Roaming Database service, which retains data independently of the game server (and allocation) lifecycle. You can sync a game session’s data to a roaming database, end the game session, then start another game session and access the same data.
Although games using a realm model often use long-lived sessions, accessing game data outside of the allocation lifecycle is still crucial for several reasons:
- You can recover the data if something goes wrong with the game server.
- You can shut down game servers to save costs when no players are connected.
- You can deploy updates to the game over time by having the next game server use a more recent build.
The independent realm lifecycle allows you to access game data outside the allocation lifecycle.
Carrying over data
You, as the developer, decide how much a persistent state carries over between later allocations of servers for the realm. Only the realm's name and other metadata persist in the simplest form. The simulation of a realm that game servers run is a blank slate seeded by those values.
In most cases, you want to carry over some state between sessions. Examples of states that make sense to persist across allocations include constructed buildings on a game map, the state of natural resources, and treasure chests.
To carry over data between sessions (allocations), you can link a realm with one or more data sources that outlive the game server using Unity Roaming Databases, a versatile embedded key-value database with durable storage.