To use Firebase with Unity, download the Firebase Unity SDK from the official GitHub releases, import the packages into your Unity project, and resolve dependencies using the External Dependency Manager (Google Resolver). You can then initialize Firebase and use services like Auth, Firestore, Analytics, and Cloud Messaging directly from C# scripts. Firebase supports both Android and iOS builds from a single Unity project.
Integrating Firebase Services into a Unity Game or App
Firebase provides a dedicated Unity SDK that wraps the native Android and iOS SDKs, giving you access to Auth, Firestore, Realtime Database, Analytics, Cloud Messaging, Crashlytics, and Remote Config from C# scripts. This tutorial covers downloading and importing the SDK, configuring platform-specific settings, initializing Firebase, and using Auth and Firestore in a Unity project.
Prerequisites
- Unity 2021.3 LTS or later installed with Android and/or iOS build support
- A Firebase project created in the Firebase Console
- google-services.json (Android) and/or GoogleService-Info.plist (iOS) downloaded from Firebase Console > Project Settings
- Basic familiarity with C# scripting in Unity
Step-by-step guide
Download and import the Firebase Unity SDK
Download and import the Firebase Unity SDK
Download the Firebase Unity SDK from the official GitHub releases page (github.com/firebase/firebase-unity-sdk/releases). The download contains .unitypackage files for each Firebase service. Import only the packages you need — typically FirebaseAuth.unitypackage, FirebaseFirestore.unitypackage, and FirebaseAnalytics.unitypackage. Importing fewer packages reduces build size and dependency conflicts.
1// Import via Unity Editor:2// Assets > Import Package > Custom Package3// Select FirebaseAuth.unitypackage4// Select FirebaseFirestore.unitypackage5// Select FirebaseAnalytics.unitypackageExpected result: Firebase plugins appear under Assets/Firebase in your Unity project. The External Dependency Manager plugin is also imported.
Add platform configuration files
Add platform configuration files
Place google-services.json in your Unity project's Assets folder for Android builds. For iOS, place GoogleService-Info.plist in Assets. These files contain your Firebase project's API keys and configuration. The Firebase SDK reads them automatically during initialization.
1// File locations:2// Assets/google-services.json (Android)3// Assets/GoogleService-Info.plist (iOS)Expected result: The config files are in the Assets root directory and recognized by the Firebase SDK.
Resolve dependencies with the External Dependency Manager
Resolve dependencies with the External Dependency Manager
The Firebase Unity SDK uses the External Dependency Manager for Unity (EDM4U) to pull native Android and iOS dependencies. After importing Firebase packages, trigger resolution manually. For Android, this downloads AAR files. For iOS, it configures CocoaPods.
1// Unity Editor menu:2// Assets > External Dependency Manager > Android Resolver > Force Resolve3// Assets > External Dependency Manager > iOS Resolver > Install CocoapodsExpected result: Android dependencies are downloaded to Assets/Plugins/Android. iOS Podfile is generated for CocoaPods.
Initialize Firebase and check dependencies
Initialize Firebase and check dependencies
Create a C# script that initializes Firebase when the game starts. The CheckAndFixDependenciesAsync method verifies that all required native dependencies are available on the device. This is critical because Firebase may fail silently on devices without Google Play Services.
1// Scripts/FirebaseInit.cs2using UnityEngine;3using Firebase;4using Firebase.Extensions;56public class FirebaseInit : MonoBehaviour7{8 public static bool IsReady { get; private set; }910 void Start()11 {12 FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task =>13 {14 if (task.Result == DependencyStatus.Available)15 {16 Debug.Log("Firebase initialized successfully");17 IsReady = true;18 }19 else20 {21 Debug.LogError($"Firebase dependency error: {task.Result}");22 }23 });24 }25}Expected result: Firebase initializes on app start and logs a success message. IsReady is true when services are available.
Implement email/password authentication
Implement email/password authentication
Use Firebase Auth to create accounts and sign in users. All Firebase Auth calls in Unity return Tasks that you can chain with ContinueWithOnMainThread to safely update Unity UI from the callback. Always check for exceptions in the task result.
1// Scripts/AuthManager.cs2using UnityEngine;3using Firebase.Auth;4using Firebase.Extensions;56public class AuthManager : MonoBehaviour7{8 private FirebaseAuth auth;910 void Start()11 {12 auth = FirebaseAuth.DefaultInstance;13 }1415 public void Register(string email, string password)16 {17 auth.CreateUserWithEmailAndPasswordAsync(email, password)18 .ContinueWithOnMainThread(task =>19 {20 if (task.Exception != null)21 {22 Debug.LogError($"Registration failed: {task.Exception.Message}");23 return;24 }25 Debug.Log($"User created: {task.Result.User.UserId}");26 });27 }2829 public void SignIn(string email, string password)30 {31 auth.SignInWithEmailAndPasswordAsync(email, password)32 .ContinueWithOnMainThread(task =>33 {34 if (task.Exception != null)35 {36 Debug.LogError($"Sign-in failed: {task.Exception.Message}");37 return;38 }39 Debug.Log($"Signed in: {task.Result.User.Email}");40 });41 }42}Expected result: Calling Register creates a new Firebase user. Calling SignIn authenticates and returns user details.
Read and write Firestore documents
Read and write Firestore documents
Use the Firestore SDK to save and retrieve game data like player profiles, scores, or inventory. Firestore in Unity uses dictionaries for document data. Always ensure Firebase is initialized before making Firestore calls.
1// Scripts/FirestoreManager.cs2using UnityEngine;3using Firebase.Firestore;4using Firebase.Extensions;5using System.Collections.Generic;67public class FirestoreManager : MonoBehaviour8{9 private FirebaseFirestore db;1011 void Start()12 {13 db = FirebaseFirestore.DefaultInstance;14 }1516 public void SavePlayerScore(string playerId, int score)17 {18 var data = new Dictionary<string, object>19 {20 { "score", score },21 { "updatedAt", FieldValue.ServerTimestamp }22 };2324 db.Collection("players").Document(playerId).SetAsync(data)25 .ContinueWithOnMainThread(task =>26 {27 if (task.Exception != null)28 Debug.LogError($"Save failed: {task.Exception.Message}");29 else30 Debug.Log("Score saved");31 });32 }3334 public void GetPlayerScore(string playerId)35 {36 db.Collection("players").Document(playerId).GetSnapshotAsync()37 .ContinueWithOnMainThread(task =>38 {39 if (task.Result.Exists)40 {41 var data = task.Result.ToDictionary();42 Debug.Log($"Score: {data["score"]}");43 }44 });45 }46}Expected result: Player scores are saved to and retrieved from Firestore documents.
Complete working example
1// Scripts/FirebaseInit.cs2using UnityEngine;3using Firebase;4using Firebase.Auth;5using Firebase.Firestore;6using Firebase.Extensions;7using System.Collections.Generic;89public class FirebaseInit : MonoBehaviour10{11 public static bool IsReady { get; private set; }12 public static FirebaseAuth Auth { get; private set; }13 public static FirebaseFirestore Db { get; private set; }1415 void Start()16 {17 FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task =>18 {19 if (task.Result == DependencyStatus.Available)20 {21 Auth = FirebaseAuth.DefaultInstance;22 Db = FirebaseFirestore.DefaultInstance;23 IsReady = true;24 Debug.Log("Firebase initialized successfully");2526 // Listen for auth state changes27 Auth.StateChanged += OnAuthStateChanged;28 }29 else30 {31 Debug.LogError($"Could not resolve Firebase dependencies: {task.Result}");32 }33 });34 }3536 private void OnAuthStateChanged(object sender, System.EventArgs e)37 {38 FirebaseUser user = Auth.CurrentUser;39 if (user != null)40 Debug.Log($"User signed in: {user.UserId}");41 else42 Debug.Log("User signed out");43 }4445 void OnDestroy()46 {47 if (Auth != null)48 Auth.StateChanged -= OnAuthStateChanged;49 }50}Common mistakes when using Firebase with Unity
Why it's a problem: Mixing Firebase Unity SDK versions, causing dependency resolution failures and build errors
How to avoid: Always download all Firebase .unitypackage files from the same SDK release. Delete old Firebase plugins before importing a new version.
Why it's a problem: Calling Firebase APIs before CheckAndFixDependenciesAsync completes, resulting in null reference exceptions
How to avoid: Gate all Firebase calls behind an IsReady check or wait for the initialization callback before accessing Auth, Firestore, or other services.
Why it's a problem: Using package name in Unity that does not match the app registered in Firebase Console
How to avoid: Ensure your Unity Player Settings > Package Name matches exactly the Android/iOS app you registered in Firebase Console > Project Settings.
Best practices
- Import only the Firebase packages you actually use to minimize build size and dependency conflicts
- Always call CheckAndFixDependenciesAsync before using any Firebase service
- Use ContinueWithOnMainThread for all Firebase callbacks to safely update Unity UI and GameObjects
- Keep google-services.json and GoogleService-Info.plist out of public repositories
- Test on real devices since the Firebase Unity SDK does not fully work in the Unity Editor for all services
- For games with complex backend requirements like matchmaking, leaderboards, and real-time state sync, RapidDev can help architect the Firebase infrastructure
- Use Firebase Analytics to track player behavior and Firebase Crashlytics to monitor crash reports in production
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
I am building a Unity game and want to use Firebase for authentication and saving player data to Firestore. Show me how to initialize Firebase in Unity, implement email/password login with FirebaseAuth, and save/load player scores from Firestore using C# MonoBehaviours.
Set up Firebase in my Unity project for Android. I need email/password authentication and Firestore for storing player profiles with fields: displayName, score, and lastLogin. Show the initialization script, auth manager, and Firestore read/write code in C# using ContinueWithOnMainThread.
Frequently asked questions
Does Firebase work in the Unity Editor?
Some services like Auth and Firestore work in the Unity Editor on desktop, but with limitations. Analytics, Crashlytics, and Cloud Messaging require a real Android or iOS device. Always test Firebase features on actual devices before release.
Can I use Firebase with Unity WebGL builds?
The Firebase Unity SDK does not support WebGL builds. For web-based Unity games, you would need to use the Firebase JavaScript SDK through a JavaScript plugin bridge, which adds significant complexity.
How do I handle Firebase on both Android and iOS from one Unity project?
Place both google-services.json (Android) and GoogleService-Info.plist (iOS) in your Assets folder. The Firebase SDK automatically uses the correct config file based on the build target. Register both platforms in the Firebase Console.
What Unity versions are supported by Firebase?
Firebase Unity SDK 12+ supports Unity 2021.3 LTS and later. Earlier Unity versions may work but are not officially supported. Always check the Firebase Unity SDK release notes for the latest compatibility information.
How do I update the Firebase Unity SDK?
Delete all existing Firebase plugins from your Assets folder (Assets/Firebase, Assets/Plugins containing Firebase files), then import the new .unitypackage files. Run Force Resolve on the External Dependency Manager after updating.
Is Firebase free for Unity games?
Firebase Auth, Analytics, Crashlytics, Cloud Messaging, and Remote Config are free regardless of scale. Firestore and Cloud Functions are free within Spark plan limits (50K reads/day, 20K writes/day). The Blaze plan charges only for usage above the free tier.
Can I use Realtime Database instead of Firestore in Unity?
Yes. The Firebase Unity SDK supports both Firestore and Realtime Database. RTDB is a good choice for real-time game state with low-latency requirements. Import FirebaseDatabase.unitypackage instead of FirebaseFirestore.unitypackage.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation