Fluid Database
raw JSON → 2.1.0 verified Sat Apr 25 auth: no javascript maintenance
A Unity package providing a simple key-value pair database supporting int, float, string, and bool types, with extensibility to custom types via generics. Current stable version is 2.1.0 (released 2021-01-05). The package is installed via Unity's Package Manager from the npm registry under the com.fluid scope. It uses Unity Events for change notifications and includes a global bool monitor component. Compared to PlayerPrefs or scriptable objects, Fluid Database offers type safety, a generic API, and editor integration.
Common errors
error error CS0246: The type or namespace name 'FluidDatabase' could not be found ↓
cause Missing using directive or package not installed.
fix
Add 'using FluidDatabase;' at top of script and ensure package is installed via package manager.
error Failed to resolve package: com.fluid.database ↓
cause Missing scoped registry in Packages/manifest.json.
fix
Add scopedRegistry for 'com.fluid' in manifest.json.
error ArgumentException: The requested value type does not match the stored type. ↓
cause Calling Get<T> with a type different from the stored type.
fix
Ensure T matches the type used in Set. Prefer using typed database (e.g., IntDatabase) instead of generic <T>.
Warnings
breaking In v2.0.0, events were replaced with Unity Event Plus. Existing components using built-in events will break. ↓
fix Update event listeners to use UnityEventPlus or migrate to the new event system.
breaking In v2.0.0, global bool monitor component now uses array values instead of single bool. Existing monitor components will lose their value. ↓
fix Re-assign the bool values in the array field of the global bool monitor.
gotcha Package requires scopedRegistry configuration. Without it, Unity cannot resolve the package from npm. ↓
fix Add scopedRegistries entry as shown in the installation instructions.
deprecated Documentation mentions old event system that was removed in v2.0.0. ↓
fix Refer to the new UnityEventPlus documentation.
Install
npm install com.fluid.database yarn add com.fluid.database pnpm add com.fluid.database Imports
- FluidDatabase wrong
using Fluid.Database;correctusing FluidDatabase; - IntDatabase wrong
IntDatabase intDb = new IntDatabase();correctpublic IntDatabase intDb = new IntDatabase(); - IDatabase<T> wrong
public class MyCustomDatabase : Database {}correctpublic class MyCustomDatabase : Database<MyType> { }
Quickstart
using FluidDatabase;
using UnityEngine;
public class Example : MonoBehaviour
{
public IntDatabase intDb;
void Start()
{
if (intDb != null)
{
intDb.Set("score", 100);
Debug.Log("Score: " + intDb.Get<int>("score", 0));
Debug.Log("Has key 'score': " + intDb.Has("score"));
}
}
}