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 name Field Type Comments
Primitives int int
long long
float float
double double
bool bool
decimal decimal
guid Guid
string string single line text
text string multiple lines text
Primitive nullable int? int?
long? long?
float? float?
double? double?
bool? bool?
guid? Guid?
Enum #4 enum Enum
enumByte Enum
enumShort Enum
enumList List<Enum>
Unity Primitives vector2 Vector2
vector3 Vector3
vector4 Vector4
quaternion Quaternion
rect Rect
bounds Bounds
color Color
ray Ray
ray2d Ray2D
keyCode KeyCode
gradient Gradient
animationCurve2017 AnimationCurve Field target Unity 2017. For Unity >= 2018, download field animationCurve2018 here
Unity Primitive nullable vector2? Vector2?
vector3? Vector3?
vector4? Vector4?
quaternion? Quaternion?
color? Color?
Unity Assets #5 unityTexture Texture
unityTexture2d Texture2D
unitySprite Sprite Can accept a single sprite, a sprite from a multiple sprite, a sprite from SpriteAtlas If you use SpriteAtlas, make sure to turn SpritePacker on (set Edit->Project settings->Editor->SpritePacker to "Always Enabled" and press on "Pack preview" button when you change your atlas)
unityMaterial Material
unityPrefab GameObject
unityFont Font
unityAudioClip AudioClip
unityObject Object Starting with v.1.5.6 additional type constraint can be added. Code generators generate proper type (using type from constraint)
List of Primitives listBool List<bool>
listDouble List<double>
listFloat List<float>
listGuid List<Guid>
listInt List<int>
listLong List<long>
listString List<string>
List of Unity Primitives listVector2 List<Vector2>
listVector3 List<Vector3>
listVector4 List<Vector4>
listQuaternion List<Quaternion>
listColor List<Color>
Dictionary hashtable #3 Hashtable
Relations relationSingle BGEntity
relationMultiple List<BGEntity>
nested List<BGEntity> read-only, #1
Unity Scene #2 entityReference BGEntityGo not recommended, use objectReference instead
entityListReference List<BGEntityGo> not recommended, use objectListReference instead
objectReference BGWithId
objectListReference 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)

Technically, it's a usual table with many-to-one relation to parent table with 2 distinct features:

  1. To access nested rows you need to choose parent row first using parent table GUI
  2. If you delete a parent row, related nested rows will also be deleted, cause they are considered as integral part of this parent row

You can read more about nested table concept here

Unity Scene Fields (#2)

Referencing scene GameObjects using objectReference/objectListReference fields is implemented with the same technique, which is used in this Unity project, by adding additional component (BGWithId) with unique ID. On Awake method object is added to the internal cache and On OnDestroy method object is removed from the cache. There are 2 restrictions, then using these fields:
  1. GameObjects can not be resolved before Awake method is called or after OnDestroy method
  2. GameObjects can be resolved only at runtime, they will not be resolved from Editor code
entityReference/entityListReference fields are considered to be obsolete and not recommended anymore (they use UnityObject.FindComponentOfType method and very 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.

Enum/enumList (#4)

With enum/enumList fields you can reference your own enumerations. Important notes:

  1. Once you created your own enum field, you can not change enum type name or namespace, cause they are stored inside database. To change it you can create exact copy of your enum with different name and change enum type at field's settings
  2. Values are stored exactly as C# store them- with numeric value. You may consider adding numeric values to your constants so constants reordering does not affect values

Unity Asset Fields (#5)

All these fields are read only. You can reference any Unity asset (UnityObject can be used to reference any asset).

Available loaders are:

Resources Asset Bundles (obsolete) Addressables Addressables by Guid
Recommendations Use it only if an amount of assets is small. Unity does not recommend to use it (more info) not recommended under any circumstances use it if you want database to store asset's address use it if you want database to store asset's Guid.
How asset is loaded using Resources.Load using AssetBundle.Load using Addressables.LoadAssetAsync
Prerequisites asset should be placed under one of Resources folder asset should be included to one of asset bundles
  1. Addressables package should be installed
  2. asset should be included to Addressables
  3. BGDatabase plugin for Addressables support should be installed
Stored value path, relative to Resources folder path within asset bundle asset address asset Guid
Limitations after asset was added to database (otherwise you need to reassign the value) path/name can not be changed name can not be changed asset address can not be changed, but you can freely move/rename asset asset Guid can not be changed (it's stored in corresponding meta file), but you can freely move/rename asset
More information Read more about Resources folder and asset bundles here Read Unity's Addressables manual here. To add support for addressables, please, download our plugin and follow setup/use manual at our download page