Partitions add-on

← Back Horizontal partitions

Description

Horizontal partitioning allows to store different rows into different files. These files are not automatically loaded at runtime, they need to be loaded/unloaded from C# scripts

Why use it?

Partition addon can be used if you have chunks of data, which is required to be loaded only in specific scenes/scenarios. So you can load this data at some event (like scene's loading) and unload it on another event (like scene unloading), thus reducing memory usage.

Restrictions

  1. Save load addon does not support saving not loaded partitioned data. Basically partitioning works well only for read-only data, cause when partition is unloaded - the data is deleted
  2. There is no way to reorder rows from different partitions, cause partition's data is loaded in specific order. Main database is loaded first, then all the partitions one-by-one, so data will always be sorted by partitions. If you changed partitioning information during editing session, press on "Reload" button after saving database to view actual rows order.
  3. Partition addon takes effect only when saving main database in Unity Editor and loading main database at runtime. It has no effect in all other scenarios
  4. Make sure, loaded/unloaded data is not referenced from main database part (e.g. no relations fields referencing partition data from main (non-partitioned) database)

How it works?

At runtime - only main database file is loaded automatically. Partition files are loaded/unloaded manually from C# scripts

        //to load a partition (partition can be index/name/ID)
        BGRepo.I.Addons.Get<BGAddonPartition>().Load(partition);

        //to unload a partition (partition can be index/name/ID)
        BGRepo.I.Addons.Get<BGAddonPartition>().Unload(partition);

Setup guide

Enable partitions addon and enable horizontal partitioning

Use Partition addon Editor GUI to enable/disable partitioning support for individual tables. Tables with partitioning support has a "dbPartition" field with certain supported field type to reference partition

  1. After enabling addon, a meta with name "DbPartition" is auto-created. Each row of this table means a separate partition
  2. If you want to "move" some table rows to some partition, "dbPartition" field is required with certain type (read more about field type below) You can create this field by clicking on "Enable" button in "NonPartitionedMetas" table
  3. Then you need to assign some valid value to this field to "move" the whole row to a certain partition.(the example below for byte? field)

Supported field types

To mark the row as belonging to some partition we use the field with name "dbPartition" and certain supported field type. Use the table below to understand the differences and how values are used

Field type ↓ Description
relationSingle Standard single row relation, referencing DbPartition table. No value- non-partitioned, any other value means it belong to a partition, it's referencing.
byte?, short?, int? Nullable number fields. No value- non-partitioned, otherwise a physical index of partition, the row belongs to
byte, short, int Simple number fields. 0- non partitioned, otherwise a physical index of partition, the row belongs to + 1. So 0 means non-partitioned, 1 means the first partition (partition with index=0) etc.

There is also a tool available (under "Tools" tab), which migrates existing nullable fields(byte?, short?, int?) to non-nullable ones (byte, short, int) and vice versa.

Unloading/releasing addressables assets

We provide an option to release/unload partition assets while unloading a partition with additional setup (read more here)

← Back to Partitions add-on