UGTK cat mascotUGTKengine within an engine Request access

UGTK / Toolkit / Data Systems / Database System Completed

Data Systems — UGTK

Database System

Summary

The Database System within the Unity Games Toolkit (UGTK) provides a flexible and generic framework for managing serializable elements in a database. It allows various types of data to be stored and managed efficiently. This system includes a generic DatabaseElement class for individual data entries and an abstract SO_Database class for creating databases as ScriptableObjects. Additionally, custom property drawers enhance the Unity Inspector experience by providing ID generation and copy functionality.


Content


Modules Dependencies

The Database System does not have external dependencies within the UGTK. It can be used independently.


Setup

To set up the Database System, follow these steps:

  1. Create a struct with [Serializable] as property. This will be your struct class to use into your database

    ```csharp

    [System.Serializable] public struct MyStruct { public int MyInt; public float MyFloat; public string MyString; }

    ```

  2. Create a class and derive the class from SO_Database<T> where T is the type of data you want to store.:

    ```csharp

    using UGTK.Data.DatabaseSystem;

    [UnityEngine.CreateAssetMenu(menuName = "UGTK/Database/MyDatabase", fileName = "MyDatabase")] public class ExampleDatabase : SO_Database { // Your class implementation here }

    ```

  3. Create Database Instance:

  1. Manipulate Database Elements:

  1. Use Elements in the project


How To Use

SO_Database\<T>

  1. Add Element (Editor only):

    SO_Database<T> database = // get your database instance
    database.AddElement("MyElementID", myData);

  1. Modify Element (Editor only):

    SO_Database<T> database = // get your database instance
    database.ModifyElement("MyElementID", newData);

  1. Modify Element (Editor only):

    SO_Database<T> database = // get your database instance
    database.ModifyElement("MyElementID", newData);

  1. Delete Element (Editor only):

    SO_Database<T> database = // get your database instance
    database.DeleteElement("MyElementID");

  1. Get Element:

SO_Database<T> database = // get your database instance
var element = database.GetElement("MyElementID");
if (element.Item1)
{
    // Element found, element.Item2 contains the data
}
else
{
    // Element not found
}

  1. Get All Elements:

SO_Database<T> database = // get your database instance
List<DatabaseElement<T>> allElements = database.GetElements();

DatabaseElement

  1. Create a Database Element:

DatabaseElement<T> newElement = new DatabaseElement<T>("MyElementID", myData);

  1. Set Element ID::

newElement.Setid("MyNewElementID");

  1. Set Element Info::

newElement.SetInfo(newData);

  1. Get Element ID:

string id = newElement.Getid();

  1. Get Element Info:

T info = newElement.GetInfo();


Testing Scene

Open DatabaseScene in the module's Debug/ folder. The scene wires an ExampleDatabaseUser to a simple and a randomic database; the grid one is an asset, in Debug/Scriptables/ExampleIntGridDatabase, and the GIF below is its inspector.

What to do, in order:

  1. Add elements to a simple database and read them back by id.
  2. Add two elements with the same id.
  3. Read an id that does not exist.
  4. Draw repeatedly from a randomic database and check the weights are respected.
  5. Select ExampleIntGridDatabase and use Grid Size: the -1 / +1 buttons on Columns and Rows resize the table under them, and the cells you already filled keep their values.

Steps 2 and 3 are the pair worth pinning down before building on top: what a duplicate id does, and whether a miss returns a default or announces itself. Step 5 also confirms the grid inspector is applying — it is registered on UGTK's own database base, so it should claim these assets and leave every other ScriptableObject in the project alone.


Technical Info

The following are the main scripts for Database System. Refer to the UML section for the detailed structure.

Scripts:


© 2026 Marcello De Bonis. All rights reserved

Real dependenciesOpen in the map →

Measured from the repository: code references (asmdef) plus prefab and asset GUIDs. Importing this module alone brings in 2 modules in total.