Show Sidebar

Room Persistence Guide

This guide explains how to persist Photon rooms data on a web server.

Concept

Although by nature Photon applications are synchronous, they can be extended to support asynchronous behaviour. Photon webhooks can be enabled and configured in a way it lets players leave and rejoin rooms seamlessly without losing game data. It is also possible to enable joining rooms asynchronously via friend invitations.

In Photon, game data is called room state. The room state is composed of:

  • Room options
  • Room Properties
  • Actors List
  • Event cache

In order to resume a left game, room state should be reconstructed. That is why the most basic and simple way of saving and loading data in Photon is to save the room state as is.

Saving Room State

To save a room state, the following webhooks settings are required:

  • BaseUrl should be an available URL.
  • IsPersistent = true.
  • PathClose should be a valid working path.

When you create rooms, these conditions need to be met:

  • RoomOptions.PlayerTTL == -1 or RoomOptions.PlayerTTL > RoomOptions.EmptyRoomTTL.
  • RoomOptions.CheckUserOnJoin = true.

When players want to leave a room without abandoning you should call Disconnect(), OpLeave() or OpLeave(true).

The room state will be sent in GameClose webhook and you will need to save it from your web server.

Loading Room State

To load a room state, the following webhooks settings are required:

  • BaseUrl should be an available URL.
  • IsPersistent = true.
  • PathCreate should be a valid working path.

To rejoin a room you should call:

If your game includes challenges and invitations you should enable AsyncJoin by setting it to true and join rooms normally by name:

From web server you need to return the previously saved room state in the webhook response.

CheatSheet

IsPersistent PathCreate PathClose RoomOptions Comment
true valid path valid path PlayerTTL == -1 && 0 <= EmptyRoomTTL Inactive players can never timeout.
Room state will always be sent unless:
  • all actors explicitly leave for good.
  • the room stays empty for EmptyRoomTTL ms.
* * * EmptyRoomTTL >= PlayerTTL >= 0 Room state will never be sent.
true valid path valid path PlayerTTL > EmptyRoomTTL >= 0 The room can only be loaded within PlayerTTL - EmptyRoomTTL ms after saving it.
false * * * Room state will never be sent.
* empty or not valid path * * Room state can never be loaded.
* * empty or not valid path * Room state can never be sent.

 To Document Top