Misc

← Back Referencing tables, fields, rows and cells

This page describes all methods for creating serializable references to tables, fields, rows and cells. For regular database access use CodeGen addon generated classes or basic API

How to reference a Method Screenshot
Table Use BGMetaReference class
Code example
using BansheeGz.BGDatabase;
using UnityEngine;

public class Temp : MonoBehaviour
{
    public BGMetaReference table;

    private void Start()
    {
        BGMetaEntity meta = table.Meta;
    }
}
Field Option #1. Use BGFieldReference class
Code example
using BansheeGz.BGDatabase;
using UnityEngine;

public class Temp : MonoBehaviour
{
    public BGFieldReference field;

    private void Start()
    {
        BGField dbField = field.Field;
    }
}
Option #2. Use field reference class, generated by CodeGen addon
Code example
using BansheeGz.BGDatabase;
using UnityEngine;

public class Temp : MonoBehaviour
{
    //D_Weapon_FieldRef class is generated by CodeGen addon
    public D_Weapon_FieldRef field;

    private void Start()
    {
        BGField dbField = field.Field;
    }
}
Row Option #1. Use MonoBehaviour generated components
Code example
using UnityEngine;

public class Temp : MonoBehaviour
{
    private void Start()
    {
        // M_Weapon is a generated class
        M_Weapon weapon = GetComponent<M_Weapon>();
        print($"Weapon {weapon.name}");
    }
}
Option #2. Use BGEntityGo component (can reference a row from any table but no generated properties/methods)
Code example
using BansheeGz.BGDatabase;
using UnityEngine;

public class Temp : MonoBehaviour
{
    private void Start()
    {
        BGEntityGo weapon = GetComponent<BGEntityGo>();
        BGEntity entity = weapon.Entity;
    }
}
Option #3. Use classes, generated by CodeGen addon ("Row reference classes postfix" parameter should be set). If you use Odin Inspector, please, read this.
Code example
using UnityEngine;

public class Temp : MonoBehaviour
{
    public D_Weapon_RowRef row;

    private void Start()
    {
        // D_Weapon class is also generated by CodeGen addon
        D_Weapon dbRow = row.Entity;
    }
}
Option #4. Use BGEntityReference class
Code example
using BansheeGz.BGDatabase;
using UnityEngine;

public class Temp : MonoBehaviour
{
    public BGEntityReference row;

    private void Start()
    {
        BGEntity dbRow = row.GetEntity();
    }
}
Cell Cell includes table, field and row. Use BGCellReference class
Code example
using BansheeGz.BGDatabase;
using UnityEngine;

public class Temp : MonoBehaviour
{
    public BGCellReference cell;

    private void Start()
    {
        BGEntity dbRow = cell.GetEntity();
        BGField dbField = cell.Field;
        print(cell.Value);
    }
}

Odin inspector and reference classes editors

If you use OdinInspector, reference classes editors can be bugged, showing table selection instead of row/field selection. The solution is to use DrawWithUnity attribute for disabling OdinInspector for your field (see the example code below).

Code example
using BansheeGz.BGDatabase;
using UnityEngine;
using Sirenix.OdinInspector;

public class Temp : MonoBehaviour
{
    [DrawWithUnity]
    public D_Weapon_RowRef row;

    private void Start()
    {
        D_Weapon dbRow = row.Entity;
    }
}
← Back to Misc