Realtime Database Examples
This section demonstrates the most common and practical usage patterns of Firebase Realtime Database in Unreal Engine projects.
Realtime Database is typically used to store and synchronize simple data structures in real time. In most projects, only a small subset of functionality is required to cover the majority of use cases.
All examples below are shown using Blueprint nodes. Firebase is assumed to be already initialized.
Providing Data to Realtime Database Operations
Realtime Database write operations (Set, Update, Push) accept both JSON strings and simple primitive values.
JSON Values
JSON should be used for structured data with multiple fields.
Common examples:
- player profile data
- grouped configuration values
Example values:
{ "level": 5, "xp": 1200 }{ "enabled": true, "mode": "hard" }
For Set, the JSON replaces the entire value at the path.
For Update, only the fields present in the JSON are modified.
Primitive Values
Primitive values can be used for simple paths that store a single value.
Common examples:
truefor feature flags42for counters"online"for simple state values
Primitive values are written directly to the specified path without wrapping them in a JSON object.
Summary
- use JSON for structured or multi-field data
- use primitive values for simple, single-value paths
Both formats are supported by Set, Update, and Push operations.
Setting Data
Writing data to Realtime Database is used to store or overwrite values at a specific path.
This pattern is commonly used for:
- player profiles
- progression data
- persistent configuration values
Important notes:
- Set Value replaces any existing data at the specified path
- the entire value at the path is overwritten
- data is provided as a JSON string
Reading Data
Reading data from Realtime Database allows you to retrieve the current value stored at a specific path asynchronously.
Important notes:
- Get Value performs an asynchronous read operation
- the returned value is provided as a JSON string
- the JSON can be parsed and used inside game logic
- failure callbacks should be handled to detect missing data or network issues
Reading data is commonly used during initialization, profile loading, or when synchronizing game state with remote data.
Updating Existing Data
In many cases, only specific fields need to be updated without overwriting the entire object.
Using Update Value allows you to:
- modify individual fields
- preserve existing data at the same path
- avoid sending the full data structure again
This approach is ideal for incremental changes such as:
- increasing experience points
- updating scores
- toggling flags
Listening for Data Changes
One of the key features of Realtime Database is the ability to listen for changes at a specific path.
When a listener is attached:
- the listener is triggered every time the value at the path changes
- the function returns a listener handle, which uniquely identifies this listener instance
- the handle must be stored if you plan to stop the listener later
- when the listener is no longer needed, it should be stopped using Stop Listener with the same handle
Listener handles allow you to precisely control the lifecycle of active listeners and avoid unnecessary updates or memory usage.
This pattern is commonly used to keep UI elements or game state synchronized with remote data in real time.
Pushing New Child Values
Realtime Database supports adding new child entries with automatically generated keys.
This is especially useful for list-based data such as:
- chat messages
- logs
- event histories
Key characteristics of pushed values:
- each entry receives a unique, auto-generated key
- existing entries are never overwritten
- data is appended in an ordered structure
The generated key uniquely identifies the created entry.
If you need to modify or remove the entry later, this key should be stored and reused when accessing the same path.
If the data is append-only and does not need to be referenced again, the generated key can be safely ignored.
This pattern is ideal for append-only data where ordering and uniqueness are important.
Summary
Firebase Realtime Database provides a simple and efficient way to store and synchronize data in real time.
By combining basic write and read operations, partial updates, value listeners, and push-based lists, you can cover most common online and synchronization scenarios without additional backend infrastructure.