Field types

Fields overview

Fields table

This is all fields types, BGDatabase currently supports (you can create your own field if it's needed.)

Field Group Field Type (Comments)









Primitive nullable







Unity Primitives











Unity Primitive nullable






Unity Assets #4

unityTexture (value type is Texture)

unityTexture2d (value type is Texture2D)

unitySprite (value type is Sprite)

unityMaterial (value type is Material)

unityPrefab (value type is GameObject)

unityFont (value type is Font)

unityAudioClip (value type is AudioClip )

unityObject (Any Unity Asset, value type is UnityEngine.Object)

List of Primitives

listBool (bool list, e.g. List<bool>)

listDouble (double list, e.g. List<double>)

listFloat (float list, e.g. List<float>)

listGuid (Guid list, e.g. List<Guid>)

listInt (int list, e.g. List<int>)

listLong (long list, e.g. List<long>)

listString (string list, e.g. List<string>)

List of Unity Primitives

listVector2 (Vector2 list, e.g. List<Vector2>)

listVector3 (Vector3 list, e.g. List<Vector3>)

listVector4 (Vector4 list, e.g. List<Vector4>)

listQuaternion (Quaternion list, e.g. List<Quaternion>)

listColor (Color list, e.g. List<Color>)

Dictionary hashtable #3

relationSingle (value type is BGEntity)

relationMultiple (value type is List<BGEntity>)

nested (value type is List<BGEntity>) #1

Unity Scene #2

entityReference (reference to entityGo, value type is BGEntityGo)

entityListReference (reference to list of entityGos, value type is List<BGEntityGo>)

objectReference (reference to UnityObject, value type is BGWithId)

objectListReference (reference to a list of UnityObjects, value type is List<BGWithId>)

Nested Field (#1)

Nested field is a special field, which creates a whole new meta (table), which has many-to-one relation to owner meta. It means, you can create a linked list with any fields that are supported by BGDatabase. It is a readonly field (to change it's value- delete or add nested Entities). To create a nested Entity use special method, which accept the owner of nested entity BGMetaNested.NewEntity(BGEntity owner). BGMetaNested is a class for nested tables (to be used instead of generic BGMetaRow)

Unity Scene Fields (#2)

There are 2 ways to reference GameObject in the scene

  1. if this object has BGEntityGo component attached. BGEntityGo is used to reference a row from a database and you can use it's id to get reference to GameObject
  2. if this object has BGWithId component attached. BGWithId is simple component with generated id, you can use this id to get reference to GameObject

Both methods use UnityObject.FindComponentOfType method and super slow.

Hashtable (#3)

Hashtable is a dictionary without generic parameters. Following types are supported as keys: int, string, bool, Guid, custom fields. Following types are not supported as values: Unity assets, relations, hashtable, nullable structs. Null values are also not supported.

Unity Asset Fields (#4)

All these fields are read only. You can reference any Unity asset (UnityObject can be used to reference any asset). This reference will be resolved by a path. It means all unity asset fields store the path to an asset. There are 3 ways this path can be properly resolved:

  1. Asset should be stored under Resources folder. This is very simple way to reference an asset. All you have to do is to place your asset under Resources folder
  2. Asset should be included in the asset bundle. This is super complicated way. To be properly resolved, asset bundle, the asset belongs to, should be properly loaded at the moment we try to query this field, otherwise null will be returned. Note, we do not manage asset bundles in any way. Also, asset bundles should be built before assets from this bundle can be properly resolved when working with BGDatabase in Editor.
  3. Use newly introduced Unity's Addressables package (which is not ready yet, still in preview). We have added experimental support for this package (built and tested against 0.3.5-preview version). Just like with asset bundles, you need to preload assets to be able to properly resolve them, but unlike asset bundles, you do not have to build addressables to resolve them while working with BGDatabase in Editor.

    To add support for addressables:
    1. Install Unity's addressables package
    2. Unpackage Assets\BansheeGz\BGDatabase\Pins\Addressables\BGDatabase.Addressables.unitypackage
    3. Unpackage Assets\BansheeGz\BGDatabase\Editor\Pins\Addressables\BGDatabaseEditor.Addressables.unitypackage

    To preload the assets, please use the following code (replace Test with actual meta name and SomeUnityField with actual field name):

           //---------- this code is tested against 0.3.5-preview version
            //find addresses to load
            IList<object> addresses = new List<object>();
            BGRepo.I.ForEachMeta(meta =>
                //find all fields with addressables loader
                List<BGStorable<string>> fieldsWithLoaders = null;
                meta.ForEachField(field =>
                    if (!(field is BGAssetLoaderA.WithLoaderI) || !(field is BGStorable<string>)) return;
                    var fieldWithLoader = (BGAssetLoaderA.WithLoaderI) field;
                    if (!(fieldWithLoader.AssetLoader is BGAssetLoaderAddressables)) return;
                    fieldsWithLoaders = fieldsWithLoaders ?? new List<BGStorable<string>>();
                    fieldsWithLoaders.Add((BGStorable<string>) field);
                if (fieldsWithLoaders == null) return;
                //find all entities with some value
                meta.ForEachEntity(entity =>
                    for (var i = 0; i < fieldsWithLoaders.Count; i++)
                        var address = fieldsWithLoaders[i].GetStoredValue(entity.Index);
                        if (!string.IsNullOrEmpty(address)) addresses.Add(address);
            //remove duplicates
            var asyncOperation = Addressables.LoadAssets<Object>(addresses, null, Addressables.MergeMode.Union);
            asyncOperation.Completed += operation =>
                //all assets are ready to use