# Realtime Database for all platforms - Firebase

**URL:** <https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885>\
**Category:** UE Marketplace\
**Tags:** unreal-engine\
**Created:** [March 5, 2017, 8:40pm UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885 "2017-03-05T20:40:59Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![gameDNA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gamedna/32/1209504_2.png) [@gameDNA](https://forums.unrealengine.com/u/gameDNA)\
**Post date:** [August 1, 2017, 8:30pm UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/21 "2017-08-01T20:30:18Z")

</div>

> [@hamuQ;744127](#):
>
> Hi Is this plugin available ? where can I get it ? thanks !

Not yet. iOS and Android versions are done and tested in 100%. I’m thinking about releasing mobile version as Early Access.

---

<div class="post-metadata">

**Author:** ![gameDNA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gamedna/32/1209504_2.png) [@gameDNA](https://forums.unrealengine.com/u/gameDNA)\
**Post date:** [August 7, 2017, 12:51pm UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/22 "2017-08-07T12:51:20Z")

</div>

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/0/6/206e5e6693115289f114d31f89e2262b15cb2076.jpeg "Introducing Firebase Realtime Database") ](https://www.youtube.com/watch?v=U5aeM5dvUpA)

**Database Core**

**Initialization**

Before making any call to the Firebase Realtime Database, first, you should execute the _Firebase Database Init_ function. If the result is a fail, study logs to find out what causes an issue.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki5.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki5.png)

**Permissions**

The Realtime Database provides a declarative rules language that allows you to define how your data should be structured, how it should be indexed, and when your data can be read from and written to. By default, read and write access to your database is restricted so only authenticated users can read or write data. To get started without setting up _Authentication_, you can configure your rules for public access. This does make your database open to anyone, even people not using your game, so be sure to restrict your database again when you set up authentication. If you do not want to use public access you can add _Firebase Authentication_ to your app to control access to the database.

**Go Online/Offline**

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki6.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki6.png)

You can manipulate whether your game is connected to the Firebase Realtime Database or not.

- **Go Online** – Resumes the connection to the Firebase Realtime Database backend after a previous _Go Offline_ call.
- **Go Offline** – Shuts down the connection to the Firebase Realtime Database backend until _Go Online_ is called.

**Purge Outstanding Writes**

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki7.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki7.png)

This function purges all pending writes to the Firebase Realtime Database server.

**Database Reference**

_Database Reference_ represents a particular location in your Database and can be used for reading or writing data to that Database location. This class is the starting point for all Database operations. After you’ve initialized it with a URL, you can use it to read data, write data, and to create new _Database Reference_ instances.

**Get Reference**

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki8.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki8.png)

You can get _Database Reference_ using one of three available functions:

- **Firebase Database Get Reference** – get a _Database Reference_ to the root of the database.
- **Firebase Database Get Reference From Path** – get a _Database Reference_ for the specified path.
- **Firebase Database Get Reference From URL** – get a _Database Reference_ for the provided URL, which must belong to the database URL this instance is already connected to.

**Tree manipulating**

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki9.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki9.png)

For more flexible tree manipulating you can use the following functions instead of paths or URLs:

- **Child** – gets a reference to a location relative to this one.
- **Get Parent** – gets the parent of this location, or get this location again if _Is Root_.
- **Get Root** – gets the root of the database.
- **Is Root** – returns true if this reference refers to the root of the database.
- **Key** – gets the string key of this database location.
- **Url** – gets the absolute URL of this reference.

The above example is an equivalent of path _/users/eclarke_ and URL _[https://fir-gamedna.firebaseio.com/users/eclarke](https://fir-gamedna.firebaseio.com/users/eclarke)_.

---

<div class="post-metadata">

**Author:** ![KillerSneak](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/killersneak/32/754802_2.png) [@KillerSneak](https://forums.unrealengine.com/u/KillerSneak)\
**Post date:** [August 8, 2017, 12:02pm UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/23 "2017-08-08T12:02:04Z")

</div>

This is a joke right? Where did this functionality go in the Ultimate Mobile Kit? Pulling the text and advertisement for it from the self pages doesn’t mean it wasn’t there when I bought the pack. Are we getting a rebate for the false advertisement?

---

<div class="post-metadata">

**Author:** ![gameDNA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gamedna/32/1209504_2.png) [@gameDNA](https://forums.unrealengine.com/u/gameDNA)\
**Post date:** [August 8, 2017, 12:43pm UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/25 "2017-08-08T12:43:29Z")

</div>

> [@KillerSneak;747187](#):
>
> This is a joke right? Where did this functionality go in the Ultimate Mobile Kit? Pulling the text and advertisement for it from the self pages doesn’t mean it wasn’t there when I bought the pack. Are we getting a rebate for the false advertisement?

Hi KillerSneak,

Realtime Database never hasn’t been advertised as part of Ultimate Mobile Kit. We have splitted Firebase functionality to separate plugins since start of development. Ultimate Mobile Kit - features for mobile only and Realtime Database - features for all platforms. For confirmation you can check start date of forum threads for Ultimate Mobile Kit (03-05-2017, 06:15 PM) and Realtime Database (03-05-2017, 08:40 PM). It was announced at the same day. “Realtime Database” words have never been used on the advertisement images of Ultimate Mobile Kit. We thought that it was clear. We announced two plugins at the same time to eliminate doubts. We are very sorry that it was still misunderstood ☹ Check your PM box, we sent you more details.

---

<div class="post-metadata">

**Author:** ![gameDNA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gamedna/32/1209504_2.png) [@gameDNA](https://forums.unrealengine.com/u/gameDNA)\
**Post date:** [August 8, 2017, 6:53pm UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/27 "2017-08-08T18:53:52Z")

</div>

**Variants**

_Firebase Variant_ is a main data type for Firebase platform and is used instead of multiple standard types such as: integer, float, string, bool, arrays, maps, etc.

**Construct Variant**

_Construct Variant_ functions create and return a new Variant from provided data type.

- **Construct From Bool** – return a Variant from a boolean.
- **Construct From Float** – return a Variant from a floating point number.
- **Construct From Integer** – return a Variant from an integer number.
- **Construct From String** – return a Variant from a string.
- **Construct Empty String** – get an empty string variant.
- **Construct Empty Array** – get a Variant containing an empty array.
- **Construct One** – get a Variant of integer value 1.
- **Construct Zero** – get a Variant of integer value 0.
- **Construct Zero Point Zero** – get a Variant of double value 0.0.
- **Construct One Point Zero** – get a Variant of double value 1.0.
- **Construct True Object** – get a Variant of bool value true.
- **Construct False Object** – get a Variant of bool value false.
- **Construct Empty Map** – get a Variant containing an empty map.
- **Construct Null** – get a Variant of type Null.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki10.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki10.png)

**Convert Variant**

You can Convert Variant from one data type to another.

- **As Bool** – get the current Variant converted into a boolean.
- **As Float** – get the current Variant converted into a floating-point number.
- **As Integer** – get the current Variant converted into an integer.
- **As String** – get the current Variant converted into a string.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki11.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki11.png)

**Check Type**

You can get and check current Variant type using below functions:

- **Type** – get the current type contained in this Variant.
- **Is Array** – get whether this Variant contains a vector.
- **Is Map** – get whether this Variant contains a map.
- **Is Null** – get whether this Variant is currently null.
- **Is Static String** – get whether this Variant contains a static string.
- **Is Mutable String** – get whether this Variant contains a mutable string.
- **Is String** – get whether this Variant contains a string.
- **Is Integer** – get whether this Variant contains an integer.
- **Is Float** – get whether this Variant contains a float.
- **Is Numeric** – get whether this Variant contains a numeric type, integer or float.
- **Is Bool** – get whether this Variant contains a bool.
- **Is Fundamental Type** – get whether this Variant contains a fundamental type: null, integer, double, bool, or one of the two string types.
- **Is Container Type** – get whether this Variant contains a container type: array or map.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki14.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki14.png)

**Get Value**

- **Bool Value** – accessor for a Variant containing a bool.
- **Float Value** – accessor for a Variant containing a float.
- **Integer Value** – accessor for a Variant containing an integer.
- **String Value** – accessor for a Variant containing a string.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki12.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki12.png)

- **Array Value** – accessor for a Variant containing an array of Variant data.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki15.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki15.png)

- **Map Value** – accessor for a Variant containing a map of Variant data.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki16.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki16.png)

**Set Value**

- **Set Bool Value** – sets the Variant to the given boolean value.
- **Set Float Value** – sets the Variant to a double-precision floating point value.
- **Set String Value** – sets the Variant to a copy of the given string.
- **Set Integer Value** – sets the Variant to an integer value.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki13.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki13.png)

- **Set Array** – sets the Variant to a copy of the given array.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki17.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki17.png)

- **Set Map** – sets the Variant to a copy of the given map.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki18.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki18.png)

---

<div class="post-metadata">

**Author:** ![gameDNA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gamedna/32/1209504_2.png) [@gameDNA](https://forums.unrealengine.com/u/gameDNA)\
**Post date:** [August 9, 2017, 10:46am UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/28 "2017-08-09T10:46:08Z")

</div>

**Read Data**

**Retrieve Data**

You can use the _Get Value_ method to read a static snapshot of the contents at a given path once. The task result will contain a snapshot containing all data at that location, including child data. If there is no data, the snapshot returned is _null_.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki19.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki19.png)

When query is completed, you can call _Value_ on downloaded _Data Snapshot_:

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki20.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki20.png)

You can manipulate database tree in downloaded Data Snapshot using child nodes:

- **Has Child** – does this Data Snapshot contain data at a particular location?
- **Child** – get a Data Snapshot for the location at the specified relative path.
- **Has Children** – does this Data Snapshot contain any children at all?
- **Children** – get all the immediate children of this location.
- **Children Count** – get the number of children of this location.
- **Exists** – returns true if the data is non-empty.
- **Key** – get the key name of the source location of this snapshot.
- **Priority** – get the priority of the data contained in this snapshot.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki21.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki21.png)

**Sorting Data**

To retrieve sorted data, start by specifying one of the order-by methods to determine how results are ordered:

- **Order By Child** – order results by the value of a specified child key.
- **Order By Key** – order results by child keys.
- **Order By Value** – order results by child values.
- **Order By Priority** – order results by child priorities.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki22.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki22.png)

The call to the _Order By Child_ method specifies the child key to order the results by. In this case, results are sorted by the value of the _price_ value in each child.  
You can only use one order-by method at a time. Calling an order-by method multiple times in the same query throws an error.

**Filtering Data**

To filter data, you can combine any of the limit or range methods with an order-by method when constructing a query.

- **Limit To First** – sets the maximum number of items to return from the beginning of the ordered list of results.
- **Limit To Last** – sets the maximum number of items to return from the end of the ordered list of results.
- **Start At** – return items greater than or equal to the specified key or value depending on the order-by method chosen.
- **End At** – return items less than or equal to the specified key or value depending on the order-by method chosen.
- **Equal To** – return items equal to the specified key or value depending on the order-by method chosen.

Unlike the order-by methods, you can combine multiple limit or range functions. For example, you can combine the _Start At_ and _End At_ methods to limit the results to a specified range of values.

Even when there is only a single match for the query, the snapshot is still a list; it just contains a single item.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki23.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki23.png)

**How query data is ordered**

**Order By Child**

When using _Order By Child_, data that contains the specified child key is ordered as follows:

- Children with a null value for the specified child key come first.
- Children with a value of false for the specified child key come next. If multiple children have a value of false, they are sorted lexicographically by key.
- Children with a value of true for the specified child key come next. If multiple children have a value of true, they are sorted lexicographically by key.
- Children with a numeric value come next, sorted in ascending order. If multiple children have the same numerical value for the specified child node, they are sorted by key.
- Strings come after numbers and are sorted lexicographically in ascending order. If multiple children have the same value for the specified child node, they are ordered lexicographically by key.
- Objects come last and are sorted lexicographically by key in ascending order.

**Order By Key**

When using _Order By Key_ to sort your data, data is returned in ascending order by key.

- Children with a key that can be parsed as a 32-bit integer come first, sorted in ascending order.
- Children with a string value as their key come next, sorted lexicographically in ascending order.

**Order By Value**

When using _Order By Value_, children are ordered by their value. The ordering criteria are the same as in _Order By Child_, except the value of the node is used instead of the value of a specified child key.

**Save Data**

**Basic write operations**

For basic write operations, you can use _Set Value_ to save data to a specified reference, replacing any existing data at that path. You can use this method to pass types accepted by JSON through a Variant type which supports:

- Null (this deletes the data)
- Integers (64-bit)
- Floating point numbers
- Booleans
- Strings
- Arrays of Variants
- Maps of strings to Variants

Using _Set Value_ in this way overwrites data at the specified location, including any child nodes. However, you can still update a child without rewriting the entire object:

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki24.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki24.png)

You can set priority of the database field which controls its sort order relative to its siblings.

In Firebase, children are sorted in the following order:

- First, children with no priority.
- Then, children with numerical priority, sorted numerically in ascending order.
- Then, remaining children, sorted lexicographically in ascending order of their text priority.

Children with the same priority (including no priority) are sorted by key: A. First, children with keys that can be parsed as 32-bit integers, sorted in ascending numerical order of their keys. B. Then, remaining children, sorted in ascending lexicographical order of their keys.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki25.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki25.png)

It’s possible to set value and priority in one function call:

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki26.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki26.png)

**Append to a list of data**

Use the _Push Child_ method to append data to a list in multiuser applications. The _Push Child_ method generates a unique key every time a new child is added to the specified Firebase reference. By using these auto-generated keys for each new element in the list, several clients can add children to the same location at the same time without write conflicts. The unique key generated by _Push Child_ is based on a timestamp, so list items are automatically ordered chronologically.

You can use the reference to the new data returned by the _Push Child_ method to get the value of the child’s auto-generated key or set data for the child. Calling _Get Key_ on a _Push Child_ reference returns the value of the auto-generated key.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki27.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki27.png)

**Update specific fields**

To simultaneously write to specific children of a node without overwriting other child nodes, use the _Update Children_ method.

When calling _Update Children_, you can update lower-level child values by specifying a path for the key. If data is stored in multiple locations to scale better, you can update all instances of that data using data fan-out. Simultaneous updates made this way are atomic: either all updates succeed or all updates fail.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki28.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki28.png)

**Delete data**

The simplest way to delete data is to call _Remove Value_ on a reference to the location of that data.

You can also delete by specifying a null Variant as the value for another write operation such as _Set Value_ or _Update Children_. You can use this technique with _Update Children_ to delete multiple children in a single API call.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki29.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki29.png)

**Transactions**

When working with data that could be corrupted by concurrent modifications, such as incremental counters, you can use a transaction operation. You give this operation the _Do Transaction_ function. This update function takes the current state of the data as an argument and returns the new desired state you would like to write. If another client writes to the location before your new value is successfully written, your update function is called again with the new current value, and the write is retried. If the transaction is rejected, the server returns the current value to the client, which runs the transaction again with the updated value. This repeats until the transaction is accepted or too many attempts have been made.

**Note 1:** Because _Run Transaction_ is called multiple times, it must be able to handle null data. Even if there is existing data in your remote database, it may not be locally cached when the transaction function is run, resulting in null for the initial value.

**Note 2:** Only one transaction can be executed at the same time.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki30.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki30.png)

**How to make the _Do Transaction_ function?**

1. Create a new Blueprint Class inherited from _Firebase Database Reference Do Transaction Proxy_.
2. Override the _Do Transaction_ function and make your own logic.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki31.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki31.png)

_Do Transaction_ is your own transaction handler, which the Firebase Realtime Database library may call multiple times to apply changes to the data, and should return success or failure depending on whether it succeeds.

This function will be called, possibly multiple times, with the current data at this location. The function is responsible for inspecting that data and modifying it as desired, then returning a _Transaction Result_ specifying either that the _Mutable Data_ was modified to a desired new state, or that the transaction should be aborted. Whenever this function is called, the _Mutable Data_ passed in must be modified from scratch.

Since this function may be called repeatedly for the same transaction, be extremely careful of any side effects that may be triggered by this function. In addition, this function is called from within the Firebase Realtime Database library’s run loop, so care is also required when accessing data that may be in use by other threads in your application.

---

<div class="post-metadata">

**Author:** ![gameDNA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gamedna/32/1209504_2.png) [@gameDNA](https://forums.unrealengine.com/u/gameDNA)\
**Post date:** [August 9, 2017, 6:42pm UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/29 "2017-08-09T18:42:38Z")

</div>

**Realtime Features**

You can add listeners to subscribe on changes in realtime to data in specified location at the database.

**Value Listener**

You can use the _On Value Changed_ callbacks to subscribe to changes to the contents at a given path. This callback is triggered once when the listener is attached and again every time the data, including children, changes. The callback is passed a snapshot containing all data at that location, including child data. If there is no data, the snapshot returned is null. A read can be canceled (_On Cancelled_) if the client doesn’t have permission to read from a Firebase database location.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki33.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki33.png)

**Important:** The _On Value Changed_ event is called every time data is changed at the specified database reference, including changes to children. To limit the size of your snapshots, attach only at the highest level needed for watching changes. For example, attaching a listener to the root of your database is not recommended.

**Child Listener**

Child events are triggered in response to specific operations that happen to the children of a node from an operation such as a new child added through the _Push Child_ method or a child being updated through the _Update Children_ method. Each of these together can be useful for listening to changes to a specific node in a database. For example, a game might use these methods together to monitor activity in the comments of a game session.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki34.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki34.png)

- **On Child Added** – the callback is typically used to retrieve a list of items in a Firebase database. The _On Child Added_ callback is called once for each existing child and then again every time a new child is added to the specified path. The listener is passed a snapshot containing the new child’s data.
- **On Child Changed** – the callback is called any time a child node is modified. This includes any modifications to descendants of the child node. It is typically used in conjunction with the _On Child Added_ and _On Child Removed_ calls to respond to changes to a list of items. The snapshot passed to the listener contains the updated data for the child.
- **On Child Removed** – the callback is triggered when an immediate child is removed. It is typically used in conjunction with the _On Child Added_ and _On Child Changed_ callbacks. The snapshot passed to the callback contains the data for the removed child.
- **On Child Moved** – the callback is triggered whenever the _On Child Changed_ call is raised by an update that causes reordering of the child. It is used with data that is ordered with _Order By Child_ or _Order By Value_.

**Remove Listeners**

You can remove attached listeners simply calling _Remove Child Listener_ or _Remove Value Listener_.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki35.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki35.png)

---

<div class="post-metadata">

**Author:** ![gameDNA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gamedna/32/1209504_2.png) [@gameDNA](https://forums.unrealengine.com/u/gameDNA)\
**Post date:** [August 10, 2017, 12:09am UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/30 "2017-08-10T00:09:59Z")

</div>

**Offline Features**

Firebase applications work even if your game temporarily loses its network connection. In addition, Firebase provides tools for persisting data locally, managing presence, and handling latency.

**Persistence Behavior**

Firebase apps automatically handle temporary network interruptions. Cached data is available while offline and Firebase resends any writes when network connectivity is restored.

When you enable disk persistence, your app writes the data locally to the device so your app can maintain state while offline, even if the user or operating system restarts the app.

You can enable disk persistence by ticking Enable Disk Persistence option in Plugin Settings:

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki36.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki36.png)

By enabling persistence, any data that the Firebase Realtime Database client would sync while online persists to disk and is available offline, even when the user or operating system restarts the game. This means your game works as it would online by using the local data stored in the cache. Listener callbacks will continue to fire for local updates.

The Firebase Realtime Database client automatically keeps a queue of all write operations that are performed while your game is offline. When persistence is enabled, this queue is also persisted to disk so all your writes are available when the user or operating system restarts the game. When the game regains connectivity, all the operations are sent to the Firebase Realtime Database server.

If your game uses Firebase Authentication, the Firebase Realtime Database client persists the user’s authentication token across game restarts. If the auth token expires while your game is offline, the client pauses write operations until your game re-authenticates the user, otherwise the write operations might fail due to security rules.

**Keeping Data Fresh**

The Firebase Realtime Database synchronizes and stores a local copy of the data for active listeners. In addition, you can keep specific locations in sync.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki37.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki37.png)

The Firebase Realtime Database client automatically downloads the data at these locations and keeps it in sync even if the reference has no active listeners. You can turn synchronization back off with the following function.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki38.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki38.png)

By default, 10MB of previously synced data is cached. This should be enough for most applications. If the cache outgrows its configured size, the Firebase Realtime Database purges data that has been used least recently. The data that is kept in sync is not purged from the cache.

**Querying Data Offline**

The Firebase Realtime Database stores data returned from a query for use when offline. For queries constructed while offline, the Firebase Realtime Database continues to work for previously loaded data. If the requested data hasn’t loaded, the Firebase Realtime Database loads data from the local cache. When network connectivity is available again, the data loads and will reflect the query.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki39.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki39.png)

**Save Data Offline**

If a client loses its network connection, your game will continue functioning correctly.  
Every client connected to a Firebase database maintains its own internal version of any active data. When data is written, it’s written to this local version first. The Firebase client then synchronizes that data with the remote database servers and with other clients on a “best-effort” basis.

As a result, all writes to the database trigger local events immediately, before any data is written to the server. This means your app remains responsive regardless of network latency or connectivity.

Once connectivity is reestablished, your game receives the appropriate set of events so that the client syncs with the current server state, without having to write any custom code.

**Handling Transactions Offline**

Any transactions that are performed while the game is offline, are queued. Once the game regains network connectivity, the transactions are sent to the Realtime Database server.

Even with persistence enabled, transactions are not persisted across game restarts. So, you cannot rely on transactions done offline being committed to your Firebase Realtime Database. To provide the best user experience, your game should show that a transaction has not been saved into your Firebase Realtime Database yet, or make sure your game remembers them manually and executes them again after a game restart.

**Managing Presence**

In realtime games it is often useful to detect when clients connect and disconnect. For example, you may want to mark a user as ‘offline’ when their client disconnects.

Firebase Database clients provide simple primitives that you can use to write to the database when a client disconnects from the Firebase Database servers. These updates occur whether the client disconnects cleanly or not, so you can rely on them to clean up data even if a connection is dropped or a client crashes. All write operations, including setting, updating, and removing, can be performed upon a disconnection.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki40.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki40.png)

When you establish an _On Disconnect_ operation, the operation lives on the Firebase Realtime Database server. The server checks security to make sure the user can perform the write event requested, and informs your game if it is invalid. The server then monitors the connection. If at any point the connection times out, or is actively closed by the Realtime Database client, the server checks security a second time (to make sure the operation is still valid) and then invokes the event.

An _On Disconnect_ event can also be canceled by _Cancel_:

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki41.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki41.png)

You can bind the following functions to _On Disconnect_:

- **Set Value** – set the value of the data at the current location when the client disconnects.
- **Set Value And Priority** – set the value and priority of the data at the current location when the client disconnects.
- **Remove Value** – remove the value at the current location when the client disconnects.
- **Update Children** – updates the specified child keys to the given values when the client disconnects.

**Detecting Connection State**

For many presence-related features, it is useful for your game to know when it is online or offline. Firebase Realtime Database provides a special location at _/.info/connected_ which is updated every time the Firebase Realtime Database client’s connection state changes. Here is an example:

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki42.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki42.png)

_/.info/connected_ is a boolean value which is not synchronized between Realtime Database clients because the value is dependent on the state of the client. In other words, if one client reads _/.info/connected_ as false, this is no guarantee that a separate client will also read false.

On Android, Firebase automatically manages connection state to reduce bandwidth and battery usage. When a client has no active listeners, no pending write or _On Disconnect_ operations, and is not explicitly disconnected by the _Go Offline_ method, Firebase closes the connection after 60 seconds of inactivity.

---

<div class="post-metadata">

**Author:** ![looter](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/looter/32/914507_2.png) [@looter](https://forums.unrealengine.com/u/looter)\
**Post date:** [August 10, 2017, 1:45am UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/31 "2017-08-10T01:45:24Z")

</div>

Is the early access version compatible with desktop game projects or is it mobile games only?

---

<div class="post-metadata">

**Author:** ![gameDNA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gamedna/32/1209504_2.png) [@gameDNA](https://forums.unrealengine.com/u/gameDNA)\
**Post date:** [August 10, 2017, 9:04am UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/33 "2017-08-10T09:04:59Z")

</div>

> [@looter;748000](#):
>
> Is the early access version compatible with desktop game projects or is it mobile games only?

Hi looter,

Early Access includes complete and tested implementation for iOS & Android. Desktop version is still under development. Initial commit with desktop version will be available later this week (not production ready yet but good for testing). If you want to use this plugin in production, I’d recommend you to wait for final release. We are honest with our fans and customers. We know that developing process is too long but Realtime Database is not trivial thing and we don’t want to release unstable software. Mobile version is production-ready so we decided to release it for people who needs it only for mobile. But desktop version needs a bit more tests and polishing. Thank you for your patience! 🙂

---

<div class="post-metadata">

**Author:** ![gameDNA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gamedna/32/1209504_2.png) [@gameDNA](https://forums.unrealengine.com/u/gameDNA)\
**Post date:** [August 10, 2017, 10:27am UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/34 "2017-08-10T10:27:00Z")

</div>

**Authentication**

Realtime Database plugin is compatible with [Ultimate Mobile Kit](https://forums.unrealengine.com/showthread.php?138716-Ultimate-Mobile-Kit-for-iOS-amp-Android-Firebase) plugin. If you use the latter, you should use its Authentication module as it is more powerful and advanced than in the Realtime Database plugin. If you haven’t purchased the Ultimate Mobile Kit or your game is designed for platforms other than mobile, you can use simple Firebase Database Authentication module described in this section.

**Initialization**

Before making any call to Authentication, you should first execute _Firebase Database Authentication Init_ function. If the result is a fail, study logs to find out what causes an issue.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki43.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki43.png)

**Create User With Email And Password**

Create a form that allows new users to register with your app using their email address and a password. When a user completes the form, validate the email address and password provided by the user, then pass them to the _Firebase Database Create User With Email And Password_ function.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki44.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki44.png)

**Send Email Verification**

You can send an address verification email to a user with the _Firebase Database Send Email Verification_ function. You can customize the email template that is used in the Authentication section of the Firebase console.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki45.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki45.png)

**Send Password Reset Email**

You can send a password reset email to a user with the _Firebase Database Send Password Reset Email_ method. You can customize the email template that is used in the Authentication section of the Firebase console. You can also send password reset emails from the Firebase console.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki46.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki46.png)

**Sign In With Email And Password**

The steps for signing in a user with a password are similar to the steps for creating a new account. When a user signs in to your game, pass the user’s email address and password to _Firebase Database Sign In With Email And Password_.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki47.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki47.png)

**Update Email**

You can set a user’s email address with the _Firebase Database Update Email_ function.

**Important:** To delete a user, the user must have signed in recently.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki48.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki48.png)

**Update Password**

You can set a user’s password with the _Firebase Database Update Password_ function.

**Important:** To delete a user, the user must have signed in recently.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki49.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki49.png)

**Sign Out**

To sign out a user from the game, call the _Firebase Database Sign Out_ function.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki50.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki50.png)

**Is User Logged In**

You can check whether a user is logged in to your game calling _Firebase Database Is User Logged In_.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki51.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki51.png)

**Reauthenticate User**

Some security-sensitive actions—such as deleting an account, setting a primary email address, and changing a password—require that the user has recently signed in. If you perform one of these actions, and the user signed in too long ago, the action fails.

When this happens, re-authenticate the user by getting new sign-in credentials from the user and passing the credentials to _Firebase Database Reauthenticate User_.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki52.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki52.png)

**Authentication Listener**

To respond to sign-in and sign-out events, attach the _RealtimeDatabase_ component to the global actor (for example Game Mode). This listener gets called whenever the user’s sign-in state changes. Because the listener runs only after the authentication object is fully initialized and after any network calls have completed, it is the best place to get information about the signed-in user. By using a listener, you ensure that the Auth object isn’t in an intermediate state — such as initialization — when you get the current user.

Sometimes user’s ID token might be changed. Event _User Id Token Changed_ is called when there is a change in the current user’s ID token.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki53.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Wiki53.png)

---

<div class="post-metadata">

**Author:** ![gameDNA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gamedna/32/1209504_2.png) [@gameDNA](https://forums.unrealengine.com/u/gameDNA)\
**Post date:** [August 10, 2017, 1:14pm UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/35 "2017-08-10T13:14:15Z")

</div>

[http://gamednastudio.com/plugins/images/RealtimeDatabase/Update1.png](https://sellfy.com/p/e9ru)

**Realtime Database Early Access**

We’ve just launched **Early Access for Realtime Database**. Early Access includes completed and tested implementation for iOS & Android. Version for other platforms is still under development and you have access to work-in-progress source code on the GitHub repository.

It includes full documentation, big example project, and is fully supported by us:

- **Documentation:** [https://gamednastudio.com/plugins/docs/RealtimeDatabase\_UserGuide.pdf](https://gamednastudio.com/plugins/docs/RealtimeDatabase_UserGuide.pdf)
- **Example Project:** [GitHub - gameDNAstudio/ExampleProjects: Example projects for gameDNA's plugins](https://github.com/gameDNAstudio/ExampleProjects)

During Early Access period you have big impact how final plugin will looks like! If you have any suggestions or feature requests, feel free to send them to us: support [at] [gamednastudio.com](http://gamednastudio.com)

**Buy now on Sellfy (Early Access): [https://sellfy.com/p/e9ru/](https://sellfy.com/p/e9ru/)**

---

<div class="post-metadata">

**Author:** ![KillerSneak](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/killersneak/32/754802_2.png) [@KillerSneak](https://forums.unrealengine.com/u/KillerSneak)\
**Post date:** [August 11, 2017, 9:17am UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/36 "2017-08-11T09:17:52Z")

</div>

Thanks for understanding.

I stand corrected. Thanks for taking the time to explain and taking the time to respond trough PM.

Again thanks for everything you have done up till now and keep up the great work. I for one am happy with your products and support, keep up the great work.

> [@gameDNA studio;747203](#):
>
> Hi KillerSneak,
> 
> Realtime Database never hasn’t been advertised as part of Ultimate Mobile Kit. We have splitted Firebase functionality to separate plugins since start of development. Ultimate Mobile Kit - features for mobile only and Realtime Database - features for all platforms. For confirmation you can check start date of forum threads for Ultimate Mobile Kit (03-05-2017, 06:15 PM) and Realtime Database (03-05-2017, 08:40 PM). It was announced at the same day. “Realtime Database” words have never been used on the advertisement images of Ultimate Mobile Kit. We thought that it was clear. We announced two plugins at the same time to eliminate doubts. We are very sorry that it was still misunderstood ☹ Check your PM box, we sent you more details.

---

<div class="post-metadata">

**Author:** ![hamuQ](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hamuq/32/723633_2.png) [@hamuQ](https://forums.unrealengine.com/u/hamuQ)\
**Post date:** [August 22, 2017, 9:05pm UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/37 "2017-08-22T21:05:49Z")

</div>

> [@gameDNA studio;744557](#):
>
> Not yet. iOS and Android versions are done and tested in 100%. I’m thinking about releasing mobile version as Early Access.

Thank you!

---

<div class="post-metadata">

**Author:** ![gameDNA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gamedna/32/1209504_2.png) [@gameDNA](https://forums.unrealengine.com/u/gameDNA)\
**Post date:** [August 27, 2017, 9:12am UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/38 "2017-08-27T09:12:49Z")

</div>

**Realtime Database 0.9.2 released!**

**We’ve just released update for plugin. You can download it from GitHub repository on releases tab or your Sellfy dashboard.**

**CHANGELOG:**

- Added ability to set placeholder timestamp value you may write into Firebase Database as a value that will automatically be populated by the Firebase Database server.

[https://gamednastudio.com/plugins/images/RealtimeDatabase/Update2.png](https://gamednastudio.com/plugins/images/RealtimeDatabase/Update2.png)

**If you haven’t owned it yet, you can buy now on [Sellfy](https://sellfy.com/p/e9ru/).**

---

<div class="post-metadata">

**Author:** ![gameDNA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gamedna/32/1209504_2.png) [@gameDNA](https://forums.unrealengine.com/u/gameDNA)\
**Post date:** [October 7, 2017, 1:45am UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/39 "2017-10-07T01:45:08Z")

</div>

**Realtime Database 0.9.3 released!**

**We’ve just released update for plugin. You can download it from GitHub repository on releases tab or your Sellfy dashboard.**

**CHANGELOG:**

- Fixed a problem with detecting Firebase Realtime Database libraries in Shipping build.
- Fixed a problem with latin characters in String Variant.

**If you haven’t owned it yet, you can buy now on [Sellfy](https://sellfy.com/p/e9ru/).**

---

<div class="post-metadata">

**Author:** ![spacegojira](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@spacegojira](https://forums.unrealengine.com/u/spacegojira)\
**Post date:** [October 7, 2017, 7:13am UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/40 "2017-10-07T07:13:28Z")

</div>

Oh my, I am so hyped for this! Thank you for working on this, I can’t wait for the release so I can test it out. 🙂

---

<div class="post-metadata">

**Author:** ![gameDNA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gamedna/32/1209504_2.png) [@gameDNA](https://forums.unrealengine.com/u/gameDNA)\
**Post date:** [October 10, 2017, 7:15pm UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/41 "2017-10-10T19:15:05Z")

</div>

Realtime Database 0.9.4 Preview for UE 4.18 Preview 3!

**We’ve just released plugin binaries for Unreal Engine 4.18 Preview 3.  
You can download it from GitHub repository on releases tab.**

**If you find any bug, feel free to report it 🙂**

**If you haven’t owned it yet, you can buy now on [Sellfy](https://sellfy.com/p/e9ru/).**

---

<div class="post-metadata">

**Author:** ![gameDNA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gamedna/32/1209504_2.png) [@gameDNA](https://forums.unrealengine.com/u/gameDNA)\
**Post date:** [October 26, 2017, 7:05pm UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/42 "2017-10-26T19:05:36Z")

</div>

[http://gamednastudio.com/plugins/images/RealtimeDatabase/Update3.png](http://gamednastudio.com/plugins/images/RealtimeDatabase/Update3.png)

Realtime Database Plugin 0.9.4 (Early Access) for UE 4.18 final release!

**We’ve just released plugin binaries for Unreal Engine 4.18  
You can download it from GitHub repository on releases tab or your Sellfy dashboard.**

**CHANGELOG:**

- Tweaks for UE 4.18 compatibility

**If you haven’t owned it yet, you can buy now on [Sellfy](https://sellfy.com/p/e9ru/)**.

---

<div class="post-metadata">

**Author:** ![gameDNA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gamedna/32/1209504_2.png) [@gameDNA](https://forums.unrealengine.com/u/gameDNA)\
**Post date:** [December 5, 2017, 8:22pm UTC](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885/45 "2017-12-05T20:22:15Z")

</div>

[http://gamednastudio.com/plugins/images/RealtimeDatabase/Update6.png](http://gamednastudio.com/plugins/images/RealtimeDatabase/Update6.png)

**Realtime Database Plugin 0.9.5 (Early Access) released!**

**We’ve just released update for Realtime Database Plugin.  
You can download it from GitHub repository on releases tab or your Sellfy dashboard.**

Please note that ANT is now deprecated and will be removed completely in the next plugins release. You should switch to Gradle.

**CHANGELOG:**

- Tweaks for UE 4.18 compatibility
- Added Android Oreo compatibility
- Added iPhone X compatibility
- Firebase C++ SDK updated to 4.3.0
- Google Play Services updated to 11.6.2 (Gradle only)
- Firebase SDK for Android updated to 11.6.2 (Gradle only)
- Google Services Plugin for Android updated to 3.1.2
- Firebase SDK for iOS updated to 4.7.0

**If you haven’t owned it yet, you can buy now on [Sellfy](https://sellfy.com/p/e9ru/)**.

[Previous page](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885.md?page=1)

[Next page](https://forums.unrealengine.com/t/realtime-database-for-all-platforms-firebase/86885.md?page=3)
