Power up your
Unity
games with our Firebase Unity SDKs.
To show how easy it is to plug Firebase into your Unity project, we made a
sample game, MechaHamster. If you want to try out adding Firebase to a game, use
the starter version that's on
GitHub
. If you want a completed version, check
out the versions in the
App Store
or the
Google Play store
.
MechaHamster (GitHub)
MechaHamster (App Store)
MechaHamster (Play Store)
Find out more information about powering up your games with Firebase at our
Firebase games page
.
Already added Firebase to your Unity project? Make sure that you're using the
latest version of the
Firebase Unity SDK
.
Prerequisites
Install Unity 2019.1 or later. Earlier versions may also be compatible but
will not be actively supported. Support for Unity 2019.1 is considered
deprecated, and will no longer be actively supported after the next major
release.
(Apple platforms only)
Install the following:
- Xcode 13.3.1 or higher
- CocoaPods 1.12.0 or higher
Make sure that your Unity project meets these requirements:
- For iOS
? targets iOS 11 or higher
- For tvOS
- targets tvOS 12 or higher
- For Android
? targets API level 19
(KitKat) or higher
If you don't already have a Unity project and just want to try out a Firebase
product, you can download one of our
quickstart samples
.
Step 1
: Create a Firebase project
Before you can add Firebase to your Unity project, you need to create a Firebase
project to connect to your Unity project. Visit
Understand Firebase Projects
to learn more about
Firebase projects.
Create a Firebase project
-
In the
Firebase console
, click
Add project
.
-
To add Firebase resources to an
existing
Google Cloud project, enter its
project name or select it from the dropdown menu.
-
To create a new project, enter the desired project name. You can also optionally
edit the project ID displayed below the project name.
-
If prompted, review and accept the
Firebase terms
.
-
Click
Continue
.
-
(Optional)
Set up Google Analytics for your project, which enables you
to have an optimal experience using any of the following Firebase products:
Either select an existing
Google Analytics account
or to create a new account.
If you create a new account, select your
Analytics reporting location
, then accept
the data sharing settings and Google Analytics terms for your project.
-
Click
Create project
(or
Add Firebase
, if you're using an
existing Google Cloud project).
Firebase automatically provisions resources for your Firebase project. When
the process completes, you'll be taken to the overview page for your Firebase
project in the Firebase console.
Step 2
: Register your app with Firebase
You can register one or more apps or games to connect with your Firebase
project.
Go to the
Firebase console
.
In the center of the project overview page, click the
Unity
icon
(
plat_unity
)
to launch the setup workflow.
If you've already added an app to your Firebase project, click
Add app
to display the platform options.
Select which build target of your Unity project that you’d like to register,
or you can even select to register both targets now at the same time.
Enter your Unity project’s platform-specific ID(s).
For iOS
? Enter your Unity project’s iOS ID in the
iOS bundle
ID
field.
For Android
? Enter your Unity project’s Android ID in the
Android package
name
field.
The terms
package name
and
application ID
are often used
interchangeably.
Where do you find your Unity project's ID?
Open your Unity project in your Unity IDE, then navigate to the settings
section for each platform:
Your Unity project's ID is the
Bundle Identifier
value
(example ID:
com.yourcompany.yourproject
).
(Optional)
Enter your Unity project’s platform-specific nickname(s).
These nicknames are internal, convenience identifiers and are only visible
to you in the Firebase console.
Click
Register app
.
Step 3
: Add Firebase configuration files
Obtain your platform-specific Firebase configuration file(s) in the
Firebase console setup workflow.
What do you need to know about this config file?
The Firebase config file contains unique, but non-secret identifiers for
your project. To learn more about this config file, visit
Understand Firebase
Projects
.
You can download your
Firebase config
file
again at any time.
Make sure the config file name is not appended with additional characters,
like
(2)
.
Open the
Project
window of your Unity project, then move your config
file(s) into the
Assets
folder.
Back in the Firebase console, in the setup workflow, click
Next
.
Step 4
: Add Firebase Unity SDKs
In the Firebase console, click
Download Firebase Unity SDK
, then unzip
the SDK somewhere convenient.
In your open Unity project, navigate to
Assets
>
Import Package
>
Custom Package
.
From the unzipped SDK, select the
supported Firebase
products
that you want to use in
your app.
Analytics enabled
- Add the Firebase package for Google Analytics:
FirebaseAnalytics.unitypackage
- Add the packages for any other Firebase products you want to use in
your app. For example, to use Firebase Authentication and
Firebase Realtime Database:
FirebaseAuth.unitypackage
and
FirebaseDatabase.unitypackage
Analytics not enabled
Add the packages for the Firebase products you want to use in your app.
For example, to use Firebase Authentication and Firebase Realtime Database:
FirebaseAuth.unitypackage
and
FirebaseDatabase.unitypackage
In the
Import Unity Package
window, click
Import
.
Back in the Firebase console, in the setup workflow, click
Next
.
Step 5
: Confirm Google Play services version requirements
The Firebase Unity SDK for Android requires
Google Play services
, which must
be up-to-date before the SDK can be used.
Add the following
using
statement and initialization code at the start of your
application. You can check for and optionally update Google Play services to the
version that is required by the Firebase Unity SDK before calling any other
methods in the SDK.
using Firebase.Extensions;
Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task => {
var dependencyStatus = task.Result;
if (dependencyStatus == Firebase.DependencyStatus.Available) {
// Create and hold a reference to your FirebaseApp,
// where app is a Firebase.FirebaseApp property of your application class.
app = Firebase.FirebaseApp.DefaultInstance;
// Set a flag here to indicate whether Firebase is ready to use by your app.
} else {
UnityEngine.Debug.LogError(System.String.Format(
"Could not resolve all Firebase dependencies: {0}", dependencyStatus));
// Firebase Unity SDK is not safe to use here.
}
});
You’re all set! Your Unity project is registered and configured to use Firebase.
If you're having trouble getting set up, though, visit the
Unity troubleshooting & FAQ
.
Set up a desktop workflow (
beta
)
When you're creating a game, it's often much easier to test your game in the
Unity editor and on desktop platforms first, then deploy and test on mobile
devices later in development. To support this workflow, we provide a
subset of the Firebase Unity SDKs
which can run
on Windows, macOS, Linux, and from within the Unity editor.
Set up a desktop-platform Unity project by following the same instructions as
for a mobile platform (start with the
Register your app with Firebase
step above).
Run your Unity project in the Unity IDE or select to build your Unity
project for
desktop
.
(Optional)
Run your Unity project in Edit Mode.
The Firebase Unity SDK can also be run in Unity's edit mode, allowing its use
in editor plugins.
When you create a
FirebaseApp
used by the editor, don't use the
default instance.
Instead, provide a unique name to the
FirebaseApp.Create()
call.
This is important to avoid a conflict in options between the instance used
by the Unity IDE and the instance used by your Unity project.
Supported Firebase products
Learn more about the Unity Firebase libraries in the
reference documentation
.
Available Firebase libraries for mobile
The Firebase Unity SDK supports the following Firebase products on
Apple
and
Android
:
Firebase product
|
Unity package
|
AdMob
|
Distributed separately in the AdMob Unity Plugin
|
Analytics
|
FirebaseAnalytics.unitypackage
|
App Check
|
FirebaseAppCheck.unitypackage
|
Authentication
|
FirebaseAuth.unitypackage
|
Cloud Firestore
|
FirebaseFirestore.unitypackage
|
Cloud Functions
|
FirebaseFunctions.unitypackage
|
Cloud Messaging
|
FirebaseMessaging.unitypackage
(recommended)
FirebaseAnalytics.unitypackage
|
Cloud Storage
|
FirebaseStorage.unitypackage
|
Crashlytics
|
FirebaseCrashlytics.unitypackage
(recommended)
FirebaseAnalytics.unitypackage
|
Dynamic Links
|
FirebaseDynamicLinks.unitypackage
(recommended)
FirebaseAnalytics.unitypackage
|
Realtime Database
|
FirebaseDatabase.unitypackage
|
Remote Config
|
FirebaseRemoteConfig.unitypackage
(recommended)
FirebaseAnalytics.unitypackage
|
Available Firebase libraries for desktop
The Firebase Unity SDK includes
desktop workflow support
for a subset of products, enabling certain parts of Firebase to be used in the
Unity editor and in standalone desktop builds on Windows, macOS, and Linux.
Firebase provides the remaining desktop libraries as stub (non-functional)
implementations for convenience when building for Windows, macOS, and Linux.
Therefore, you don't need to conditionally compile code to target the desktop.
Next steps