Save Load


Save/Load addon enable you to save/load the state of the database to/from byte array. You can define which table and which fields you want to be saved/loaded. You can find Save Load addon under Addons->Save Load.

Using Merge settings

Using Merge settings you can chose which data to save/load. You want as less data to be saved as possible. You do not need to include data, that is "static" and can not be changed during play session.

The rules are very simple:

  1. If you have some field, which value can be changed during the play session and you want this change to be persistent, you need to mark this field to be included to save/load. Example from our example scenes: we want the amount of gold, player gathered to be remembered between game sessions- so we marked this field to be saved and loaded.
  2. If you have some table, whose rows can be changed during gameplay and you want these changes to be remembered, you need to mark this table to be included to the save/load by setting following setting to true: "Add missing", "Remove Orphaned", "Update matching". These setting will ensure, that all rows from this table will be saved and loaded. Example from our example scenes: Collectable table rows can be changed, so we marked them as described above.

Merge settings for this addon is the same as merge settings for Export/Import. You can learn more about merge settings here

How to use

//to save
byte[] bytes = BGRepo.I.Addons.Get<BGAddonSaveLoad>().Save();

//to load
You can declare you MonoBehavior script to be a receiver of BeforeSave event, so the could update the database before saving (code from example project)
//this class implement BGAddonSaveLoad.BeforeSaveReciever interface,
//so OnBeforeSave method will be called before saving
public class BGPlayer : BGM_Player, BGAddonSaveLoad.BeforeSaveReciever
    //this method is called before saving
    void BGAddonSaveLoad.BeforeSaveReciever.OnBeforeSave()
        //save current position , rotation and scene to the database
        m_position = transform.position;
        m_rotation = transform.rotation;
        m_scene = BGE_Scene.FindEntity(scene => string.Equals(scene.Name, SceneManager.GetActiveScene().name));