Setup guide
- Import the package
- Starting with Unity version 2022, API updater window should pop up. Make sure to press "Yes".
-
Open
Window->BGDatabase
. Click onCreate new database file
. Choose the loader (Resources or StreamingAssets) and pressCreate
button -
Select
Configuration
tab and create a table (meta) - Add fields
-
Select
Database
tab and create rows (entities) for tables. Save the database. - To prevent data loss, commit the database file to your source control system or create regular backups.
Video guide
Which loader should you choose?
- Resources loader: this is the recommended option.
- StreamingAssets loader: use it if you need to update the database file without rebuilding your game.
- Custom loader: select this option if you need to load the database from a custom location and are comfortable implementing your own loading logic.
You can switch between the Resources and StreamingAssets loaders by moving your database file (bansheegz_database.bytes) between the Resources and StreamingAssets folders. If you're using the localization or partition addon, move all other files (bansheegz_database*.bytes) as well. Ensure you move the corresponding .meta files as well or move the files directly within the Unity Editor.
Resources (recommended) | StreamingAssets | Custom | |
---|---|---|---|
File location | Under one of Resources folders | Under Assets/StreamingAssets folder | Anywhere in your project |
Pros | Works seamlessly everywhere | Update the database file without rebuilding your game. |
|
Cons | Storing many assets under the Resources folders (which Unity doesn't recommend) may slow down database loading. |
|
|
How to enable | File bansheegz_database.bytes should be placed under one of Resources folders | File bansheegz_database.bytes should be placed under Assets/StreamingAssets folder | Read the guide below |
Database file details
BGDatabase operates with two different file types:
- Database data file
- User settings file
See the table below for more details.
↓ Feature\File → | Database file | Settings file |
---|---|---|
Purpose | Database file | User settings file |
Default name | bansheegz_database.bytes | BGS_{database asset GUID}.json |
Format | Binary | Json |
Available at runtime | Yes | No |
Shared between developers | Yes | No, each developer has a separate file |
Location | Under Resources / StreamingAssets folders | Under Documents folder |
How to change location | Move (not copy) database file along with its meta file | N/A |
How file is resolved | Naming convention is used (bansheegz_database.bytes) | File location is resolved using database asset GUID |
You can create a single, shared settings file for all team members by placing bansheegz_database_settings.json file next to database file (only resources loader is currently supported). If you're using both Google Sheets and a shared settings file, exclude bansheegz_database_settings.json from your build using third-party tools or this package, because settings file can contain sensitive data.
Custom loader implementation guide
Follow these steps:- Override the database location in the Unity Editor.
- Load the database content manually at runtime and pass it to BGDatabase.
Step 1: Overriding the database location in the Unity Editor
- Exit Unity
- Back up your database files
- Move all database files (e.g., bansheegz_database*.bytes* ) to any location within your project (except Resources and StreamingAssets folders)
- Open bansheegz_database.bytes.meta file in a text editor and replace its
guid
with the following value 3637ea689da0cff4b8d5c0fb5d609c15 - Open Unity and click on
Reload
button in the BGDatabase window. - Select "Settings->Main>Database files" and ensure the database is loaded from the custom location and the Loader is set to Custom. Verify that all content is properly loaded.
Step 2: Loading database content manually at runtime
- Load database content from your desired location and call
BGRepo.SetDefaultRepoContent(byte[] content)
method followed byBGRepo.Load()
before accessing database. - If you're using localization/partition add-ons, you also need to load all localization/partition files as well
and use
BGRepo.SetDefaultRepoContentModel(BGRepoCustomLoaderModel model)
method instead.
//content is database file content
byte[] content = someContent; //todo load content
BGRepo.SetDefaultRepoContent(content);
BGRepo.Load();
Example projects
Two example projects demonstrate loading the database file(s) from Addressables.