Skip to content

Beamable Serializer

The Beamable Serializer uses a combination of ‘cloud save’ and ‘inventory save’ to save content state. Some content needs to be saved to the cloud storage because it is not IdleKit ‘content’ but rather classes that need to save state. IUserSavedData and SerializedDataCache are examples of these. Items in the Beamable inventory are sent directly to Beamable without being cached to disk like cloud saved items.

Cloud Save - How it works

Some content needs to be saved to Cloud Storage because it is not IdleKit “content” but rather classes that need to store state. In practice this is generally saved data - IUserSavedData and IEventSettingsSavedData are examples of these. Cloud saved items get written to disk as unstructured JSON in BeamableSerializer.Serialize, which then gets sent to Beamable in regular intervals through Beamable’s CloudSavingService. Location of that local storage is device dependant, and is set as the _path variable in Beamable.cs.

Inventory Save - How it works

Inventory data is serialized and sent to Beamable by default once every 5 seconds through BeamableSerializer.SerializeDirty, which then calls UpdateInventoryAsync to send the current inventory update to Beamable. The default serialization interval can be changed through the SetSerializationInterval method in the SerializationService if five seconds is too frequent. Serialization also occurs when any major event happens (milestone completed, generator purchased, etc).

Cloud Save - how to save a new item

Items to be stored in the Cloud Inventory need to inherit from ICloudSavedData. This interface is used to mark an ISavedData as cloud saved data so that the Beamable Serializer will save this as unstructured JSON instead of in the Beamable inventory system.

Inventory Save - How to save a new item

When creating a new item in IdleKit - whether it’s a new goal, currency, promo, boost, etc, generally you need three classes - NewItem.cs, NewItemData.cs, NewItemDataAsset.cs. This is explained more here. The important thing to keep in mind when using Beamable as a backend is that any entity that has its own saved data, it's NewItemDataAsset class needs to inherit from IKItemContent, which is an implementation of Beamable’s ItemContent class. If instead it is a simple entity with no saved data class, its NewItemDataAsset class should instead inherit from IKContent. The difference between these two is that inheriting frommIKItemContent makes your new entity an 'item' in the Beamable inventory, which allows it to save data in the Beamable item inventory. Additionally there is a specialized IKEventContent which should be used when creating a custom EventContent class. Creating the required Sheets for these new classes is explained more here.