Erste Schritte mit Firebase Realtime Database für Unity
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Firebase Realtime Database speichert und synchronisiert Daten mit unserer NoSQL-Cloud-Datenbank. Daten werden in Echtzeit über alle Clients synchronisiert und bleiben verfügbar, wenn die App offline geht.
Hinweis
Bevor Sie Realtime Database verwenden können, müssen Sie Folgendes tun:
Registrieren Sie Ihr Unity-Projekt und konfigurieren Sie es für die Verwendung von Firebase.
Wenn Ihr Unity-Projekt bereits Firebase verwendet, ist es bereits für Firebase registriert und konfiguriert.
Wenn Sie kein Unity-Projekt haben, können Sie eine Beispiel-App herunterladen.
Fügen Sie Ihrem Unity-Projekt das FirebaseUnity SDK (insbesondere FirebaseDatabase.unitypackage) hinzu.
Das Hinzufügen von Firebase zu Ihrem Unity-Projekt umfasst Aufgaben sowohl in der Firebase-Konsole als auch in Ihrem geöffneten Unity-Projekt. Sie laden beispielsweise Firebase-Konfigurationsdateien aus der Konsole herunter und verschieben sie dann in Ihr Unity-Projekt.
Datenbank erstellen
Rufen Sie in der Firebase-Konsole den Bereich Realtime Database auf.
Sie werden aufgefordert, ein vorhandenes Firebase-Projekt auszuwählen.
Folgen Sie dem Workflow zur Datenbankerstellung.
Wählen Sie einen Startmodus für Ihr Firebase Security Rules aus:
Testmodus
Gut für die ersten Schritte mit den Mobil- und Web-Clientbibliotheken, allerdings können Ihre Daten von beliebigen Personen gelesen und überschrieben werden. Prüfen Sie nach dem Test den Abschnitt Firebase Realtime Database-Regeln verstehen.
Wählen Sie „testmode“ aus, um mit dem Web-, Apple- oder Android-SDK zu beginnen.
Sperrmodus
Verweigert alle Lese- und Schreibvorgänge von Mobil- und Webclients.
Ihre authentifizierten Anwendungsserver können weiterhin auf Ihre Datenbank zugreifen.
Wählen Sie einen Speicherort für die Datenbank aus.
DATABASE_NAME.firebaseio.com (für Datenbanken in us-central1)
DATABASE_NAME.REGION.firebasedatabase.app
(für Datenbanken an allen anderen Standorten)
Klicken Sie auf Fertig.
Wenn Sie Realtime Database aktivieren, wird auch die API im Cloud API Manager aktiviert.
Öffentlichen Zugriff einrichten
Die Realtime Database bietet eine deklarative Regelsprache, mit der Sie definieren können, wie Ihre Daten strukturiert und indexiert werden sollen und wann Ihre Daten gelesen und geschrieben werden können.
[null,null,["Zuletzt aktualisiert: 2025-08-23 (UTC)."],[],[],null,["\u003cbr /\u003e\n\nThe Firebase Realtime Database stores and synchronizes data with our NoSQL cloud\ndatabase. Data is synced across all clients in realtime, and remains available\nwhen your app goes offline.\n\nBefore you begin\n\nBefore you can use\n[Realtime Database](/docs/reference/unity/namespace/firebase/database),\nyou need to:\n\n- Register your Unity project and configure it to use Firebase.\n\n - If your Unity project already uses Firebase, then it's already\n registered and configured for Firebase.\n\n - If you don't have a Unity project, you can download a\n [sample app](//github.com/google/mechahamster).\n\n- Add the [Firebase Unity SDK](/download/unity) (specifically, `FirebaseDatabase.unitypackage`) to\n your Unity project.\n\n| **Find detailed instructions for these initial\n| setup tasks in\n| [Add Firebase to your Unity project](/docs/unity/setup#prerequisites).**\n\nNote that adding Firebase to your Unity project involves tasks both in the\n[Firebase console](//console.firebase.google.com/) and in your open Unity project\n(for example, you download Firebase config files from the console, then move\nthem into your Unity project).\n\nCreate a Database\n\n1. Navigate to the **Realtime Database** section of the\n [Firebase console](https://console.firebase.google.com/project/_/database).\n You'll be prompted to select an existing Firebase project.\n Follow the database creation workflow.\n\n2. Select a starting mode for your Firebase Security Rules:\n\n Test mode\n\n : Good for getting started with the mobile and web client libraries,\n but allows anyone to read and overwrite your data. After testing, **make\n sure to review the [Understand Firebase Realtime Database Rules](/docs/database/security)\n section.**\n\n :\n | **Note:** If you create a database in Test mode and make no changes to the default world-readable and world-writeable Rules within a trial period, you will be alerted by email, then your database rules will deny all requests. Note the expiration date during the Firebase console setup flow.\n\n : To get started with the web, Apple, or Android SDK, select testmode.\n\n Locked mode\n\n : Denies all reads and writes from mobile and web clients.\n Your authenticated application servers can still access your database.\n\n3. Choose a location for the database.\n\n Depending on the\n [location of the database](/docs/projects/locations#rtdb-locations), the\n URL for the new database will be in one of the following forms:\n - \u003cvar translate=\"no\"\u003eDATABASE_NAME\u003c/var\u003e`.firebaseio.com` (for\n databases in `us-central1`)\n\n - \u003cvar translate=\"no\"\u003eDATABASE_NAME\u003c/var\u003e`.`\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e`.firebasedatabase.app`\n (for databases in all other locations)\n\n4. Click **Done**.\n\nWhen you enable Realtime Database, it also enables the API in the\n[Cloud API Manager](https://console.cloud.google.com/projectselector/apis/api/firebasedatabase.googleapis.com/overview).\n\nSetting up public access\n\nThe Realtime Database provides a declarative rules language that allows you to\ndefine how your data should be structured, how it should be indexed, and when\nyour data can be read from and written to.\n| **Note:** 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](/docs/auth), you can [configure your rules for public access](/docs/rules/basics#default_rules_locked_mode). This does make your database open to anyone, even people not using your app, so be sure to restrict your database again when you set up authentication.\n\nNext Steps\n\n- Learn how to [structure data](/docs/database/unity/structure-data) for Realtime Database.\n\n- [Scale your data across multiple database\n instances.](/docs/database/usage/sharding)\n\n- [Save data.](/docs/database/unity/save-data)\n\n- [Retrieve data.](/docs/database/unity/retrieve-data)\n\n- [View your database in the\n Firebase console.](//console.firebase.google.com/project/_/database/data)\n\n- Prepare to launch your app:\n\n\n - Set up [budget\n alerts](/docs/projects/billing/avoid-surprise-bills#set-up-budget-alert-emails) for your project in the Google Cloud console.\n - Monitor the [*Usage and billing*\n dashboard](//console.firebase.google.com/project/_/usage) in the Firebase console to get an overall picture of your project's usage across multiple Firebase services. You can also visit the [Realtime Database *Usage*\n dashboard](//console.firebase.google.com/project/_/database/usage) for more detailed usage information.\n - Review the [Firebase launch checklist](/support/guides/launch-checklist)."]]