Adding Firebase to your Unity Projectplat_iosplat_androidplat_unity

Overview

Power up your Unity games with our Firebase Unity SDKs.

  • With Analytics learn how players are experiencing your game, how much time they spend playing, how long they take to complete levels, how much in-app content they're purchasing and much more.
  • Dynamic Links lets you share content like custom levels, in-game items, and game invitations between players.

  • Using Cloud Messaging you can release new content and send push notifications to players who have completed your available content.

  • Remote Config allows on the fly adjustment of gameplay settings like enemy density, power-up frequency, or anything else you want to control.

  • Realtime Database stores user-generated content like custom maps safely in the cloud.

  • Cloud Storage delivers downloadable content to your players using our secure service.

Download the SDK


Find out more about how you can power up your games, at our Firebase games page.

Features

The following features are supported by the Firebase Unity SDK on iOS and Android:

Feature Unity Package
AdMob Distributed separately in the AdMob Unity Plugin
Analytics FirebaseAnalytics.unitypackage
Authentication FirebaseAuth.unitypackage
Realtime Database FirebaseDatabase.unitypackage
Dynamic Links FirebaseDynamicLinks.unitypackage
Invites FirebaseInvites.unitypackage
Cloud Messaging FirebaseMessaging.unitypackage
Remote Config FirebaseRemoteConfig.unitypackage
Cloud Storage FirebaseStorage.unitypackage

To show how easy it is to plug Firebase into your Unity project we made a sample game 'MechaHamster' that you can download from Github and the Google Playstore (see links below)

MechaHamster Github MechaHamster Playstore

Setup for iOS

Prerequisites

  • Unity 5.3 or later.
  • Xcode 7.0 or later.
  • For Cloud Messaging:
    • A physical iOS device
    • APNs certificate with Push Notifications enabled
  • CocoaPods 1.0.0 or later.
  • A Unity project bundle identifier.

If you don't have a Unity project already, you can download one of our quickstart samples if you just want to try a Firebase feature. If you're using a quickstart, remember to get the bundle identifier from the project settings, you'll need it for the next step.

Add Firebase to your app

It's time to add Firebase to your app. To do this you'll need a Firebase project and a Firebase configuration file for your app.

  1. Create a Firebase project in the Firebase console, if you don't already have one. If you already have an existing Google project associated with your mobile app, click Import Google Project. Otherwise, click Create New Project.
  2. Click Add Firebase to your iOS app and follow the setup steps. If you're importing an existing Google project, this may happen automatically and you can just download the config file.
  3. When prompted, enter your app's bundle ID. It's important to enter the bundle ID your app is using; this can only be set when you add an app to your Firebase project.
  4. At the end, you'll download a GoogleService-Info.plist file. You can download this file again at any time.

Add the SDK to your app

  1. If you don't have a Unity project yet, create one now. You can also use one of the quickstart samples to try out a Firebase feature.
  2. Download the Firebase Unity SDK and unzip it somewhere convenient.
  3. Open your Unity project in the Unity editor.

    • Select the File > Open Project menu item.
    • Click Open.
    • Navigate to the app directory in the file dialog and click Open.
  4. Import the Firebase feature plugin, for example Firebase Analytics.

    • Select the Assets > Import Package > Custom Package menu item.
    • Import FirebaseAnalytics.unitypackage from the Firebase Unity SDK, downloaded previously.
    • Click the Import when the Import Unity Package window appears.
  5. Add the GoogleService-Info.plist file to the project.

    • Drag the GoogleService-Info.plist downloaded from the Firebase console into any folder in the Unity project.
  6. Build for iOS

    • Select the File > Build Settings menu option.
    • Select iOS in the Platform list.
    • Click Switch Platform to select iOS as the target platform.
    • Wait for the spinner (compiling) icon to stop in the bottom right corner of the Unity status bar.
    • Click Build and Run.

Setup for Android

  • Unity 5.3 or higher.
  • A device running Android 4.0 (Ice Cream Sandwich) or newer.
  • A Unity project bundle identifier.

If you don't have a Unity project already, you can download one of our quickstart samples if you just want to try a Firebase feature. If you're using a quickstart, remember to get the bundle identifier from the project settings, you'll need it for the next step.

Add Firebase to Your app

To add Firebase to your app you'll need a Firebase project and a Firebase configuration file for your app.

  1. Create a Firebase project in the Firebase console, if you don't already have one. If you already have an existing Google project associated with your mobile app, click Import Google Project. Otherwise, click Create New Project.
  2. Click Add Firebase to your Android app and follow the setup steps. If you're importing an existing Google project, this may happen automatically and you can just download the config file.
  3. When prompted, enter your app's package name. It's important to enter the package name your app is using; this can only be set when you add an app to your Firebase project.
  4. At the end, you'll download a google-services.json file. You can download this file again at any time.

Add the SDK to your app

  1. If you don't have a Unity project yet, create one now. You can also use one of the quickstart samples to try out a Firebase feature.
  2. Download the Firebase Unity SDK and unzip it somewhere convenient.
  3. Open your Unity project in the Unity editor.

    • Select the File > Open Project menu item.
    • Click Open.
    • Navigate to the app directory in the file dialog and click Open.
  4. Import the Firebase feature plugin, for example Firebase Analytics

    • Select the Assets > Import Package > Custom Package menu item.
    • Import FirebaseAnalytics.unitypackage from the Firebase Unity SDK, downloaded previously.
    • Click the Import when the Import Unity Package window appears.
  5. Add the google-services.json file to the project.

    • Drag the google-services.json downloaded from the Firebase console into any folder in your project.
  6. Build for Android

    • Select the File > Build Settings menu option.
    • Select Android in the Platform list.
    • Click Switch Platform to select Android as the target platform.
    • Wait for the spinner (compiling) icon to stop in the bottom right corner of the Unity status bar.
    • Click Build and Run.

Stub Implementations for the Editor

Stub (non-functional) implementations are provided for convenience when building for Windows, OSX and Linux so that you don't need to conditionally compile code when also targeting the desktop.

Known Issues

None.

Support

Firebase Support

Send feedback about...

Need help? Visit our support page.