Skip to content

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

All Realtime Database write operations (Set, Update, Push) accept data exclusively in the form of FirebaseValue.

This plugin does not operate on raw JSON strings or primitive values when working with Realtime Database. Instead, all data must be explicitly constructed using typed Firebase Value nodes.

FirebaseValue

A FirebaseValue represents a single typed value written to or read from Realtime Database.

Firebase values are used for all data types, including:

  • primitive values
  • arrays
  • nested objects

FirebaseValue supports the following value types:

  • integers
  • booleans
  • doubles
  • strings
  • arrays
  • objects
  • null

Values are created explicitly using Firebase Value maker nodes and can later be inspected using typed getters.

Practical Notes

  • simple values such as numbers, strings, or booleans must still be wrapped in a FirebaseValue
  • structured data must be represented using FirebaseValue instances of type Object or Array
  • a Realtime Database path always stores exactly one FirebaseValue

This explicit value construction ensures predictable data structure, type safety, and consistent behavior across all Realtime Database operations.


Setting Data

Writing data to Realtime Database is used to store or overwrite a value at a specific path.

This pattern is commonly used for:

  • player profiles
  • progression data
  • persistent configuration values

Data provided to Set Value must be constructed as a FirebaseValue.

A typical workflow is:

  • create primitive Firebase values using value maker nodes
  • combine them into an object or array value if needed
  • pass the resulting FirebaseValue to Set Value

Important notes:

  • Set Value replaces any existing data at the specified path
  • the entire value at the path is overwritten
  • even simple values must be wrapped in a FirebaseValue

Reading Data

Reading data from Realtime Database allows you to retrieve the current value stored at a specific path asynchronously.

Get Value always returns a single FirebaseValue, representing the value currently stored at the specified path.

Important notes:

  • Get Value performs an asynchronous read operation
  • the returned data is provided as a FirebaseValue
  • the value must be explicitly inspected using Firebase Value getter nodes
  • object values can be decomposed into fields using Get Object and key lookup

A common pattern is to treat the returned FirebaseValue as an object, extract individual fields by key, and then convert them to native types using typed getters.

Reading data is commonly used during initialization, profile loading, or when synchronizing game state with remote data.


Updating Existing Data

In many cases, only a specific part of an existing data structure needs to be updated without overwriting the entire value stored at a path.

Using Update Value allows you to update a value at a more specific, nested path inside an existing structure.

A typical workflow is:

  • write an initial object using Set Value
  • later update individual fields by targeting a deeper path

Important notes:

  • Update Value modifies only the value at the specified path
  • parent objects and sibling fields remain unchanged
  • the provided data must be a FirebaseValue
  • the updated path may point to an object field or a nested primitive value

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.