Getting Started with Firebase for Unity – Firecasts

Getting Started with Firebase for Unity – Firecasts
ArticlesBlog


ABE HASKINS: Hey there,
Unity developers. Do you want a game which has
detailed user-based analytics, a game which you can tweak and
run experiments on remotely, a game which is social and
sharable from the start? Well, you’ve come
to the right place. Let’s get started with
Firebase and Unity on this episode of “Firecasts.” [MUSIC PLAYING] We’re going to cover five steps
to go from an empty Unity game to a game that’s ready to be
shipped on iOS and Android. First, we’ll open
up a Unity project. Second, we’ll download
the Firebase SDK. Third, we’ll install that
Firebase SDK into Unity. Fourth, we’ll configure
a new Firebase project to be used in our Unity game. And fifth, we’ll compile our
game for iOS and Android. Are you ready? Let’s get started. First, open up the Unity editor. In our case, we’ll
be making a new game. But don’t worry if you already
have an existing game which you want to add Firebase to. The process is going
to be exactly the same. Just open up your existing game
instead of making a new one, like I’m doing. Once we’ve opened
our project, we’ll see the editor with
the inspector scene view and everything
else you’d expect. Note the empty inspector
on the right side. This is where our
Firebase panel will live once the SDK is installed. But before Firebase can start
adding cool features to Unity, we need to install Firebase. Let’s hop over to the Firebase
docs and download the latest Firebase SDK for Unity. At this point, you
probably already know if you want to make an iOS game
or an Android game or both. But the great part
about Unity is that we can make a game that
works for both these platforms with only one code base. This means that regardless
of the mobile platform you want to build for, you’ll
download just the one SDK, the Firebase SDK for Unity. This download comes as a ZIP. And when you extract it, you’ll
see a bunch of files with a .unity package extension. Let’s take a second to talk
about Unity asset packages. These packages are a standard
way in the Unity world to distribute reusable code. If you’re familiar with
other programming tools, you’ve probably included
an external library into a project. Unity asset packages
are a lot like this. It’s a way to distribute things
for other developers to use. It’s worth understanding that a
Unity asset package can contain lots of different stuff. It’s not just code,
like a normal library. Asset packages can contain
images, textures, 3D models, examples, and yes, code. Firebase has a lot of features. And you don’t need to use
all of them in your game. Each Firebase feature has
its own asset package. So if you only want to
use Firebase Analytics or you only want to
use Firebase Database, you can include
just that package. Let’s go with the simplest
feature to implement, Firebase Analytics. In the Unity editor,
go to Assets, Import Package, Custom Package. Then browse to where you
extracted the Firebase SDK and select the
FirebaseAnalytics.unity package file. Unity will take a moment
to extract the package. Then you’ll be
prompted to select which files from the
package you want to import. We can see this asset package
taking advantage of the fact that asset packages can
contain non-code assets. The first thing to
show up in this package are a bunch of icons which
are used for the Unity editor plugin. We don’t need to pick and
choose what to import here. So just click Import and
let Unity do its magic. After another second, you’ll
be back in the Unity editor. But it’ll have a
few key changes. First, your Assets folder will
allow contain some new folders. And second, your editor now has
the Firebase plugin enabled. Once the spinner in the
bottom right has stopped, you’ll be able to
start using Firebase. If you haven’t already,
it’s a good time to save your Unity scene. If you’re working
off a new project, this won’t be done
automatically. So just go to File, Save Scene. This will save the
scene in your project. And if you don’t
know what to call it, just call it something exciting
and original, like “Game.” Once we have a saved scene, we
can bring out the Firebase pane in our editor. In your menu, go to Window
and click on Firebase. Now, depending on
your editor setup, the Firebase pane may show
up as a floating window, or it may show up near
the Inspector tab. Just find it, wherever it is. The Firebase plugin
will help you get started with
any Firebase feature by linking you to setup guides,
code samples, and the API reference. You’ll notice the
very first thing the plugin shows is
advice on connecting your game to your Firebase
project’s Android or iOS app. Like I talked
about before, Unity has the ability to build
games for iOS and Android. Firebase and Unity both work
great on these platforms. But there is some
minor work needed to set up both of these
platforms for your Firebase and Unity project. Let’s start by making a new
project on the Firebase console at firebase.google.com. Once you’ve created
a project, you’ll be greeted with a
screen asking you if you’d like to make an iOS
app, an Android app, or a web app. A Firebase project
may contain many apps. This means you’ll only
need one Firebase project, even if you’re building
both an Android and iOS version of the same game. I’ll be showing you how to
build a cross-platform game. But if you’re only
interested in iOS or Android, you can just do that one. Let’s click on the Add Firebase
to Your iOS App button. We’ll enter a few basic details. And then on step two, it’ll
download a GoogleServices.plist file. This is a
configuration file that will tell the Firebase Unity
SDK what project to connect to. Back in Unity, we’ll
drag this plist file into the root of
our Assets folder. And the Firebase SDK will
automatically detect it when we build our app for iOS. This is another
situation when you need to watch that spinner
in the bottom right and make sure it’s completed. If you want to do the
same thing on Android, then click on the Add Firebase
to Your Android App button and enter that same
basic information. And the second step, you’ll
be given a GoogleServices.json file. And just like with
the plist, we’ll drag this file into the root
of our Assets folder in Unity. Once you’ve gotten your
configurations in place, you’ll be able to go into
your file Build and Run menu and build your game. Switching between
platforms is as easy as selecting that Switch
Platform buttons in the Build Settings menu. Once we have deployed our
game, the debug messages will show us that
Firebase Analytics is enabled and reporting
back to your console. Congrats. You’ve gotten your first
Firebase library up and running inside of your Unity game. But this is really
just the start. There’s a lot more Firebase
can do inside of Unity, like saving your users’
data to the cloud with the real-time
database, tweaking game play settings on the fly with
Firebase Remote Config, adding notification support with
Firebase Cloud Messaging, and a whole lot more. If you want to learn more about
what Firebase and Unity can do together, check out our Unity
docs, linked in the description below, and subscribe to the
Firebase YouTube channel. In the meantime,
thanks for watching. I’m heading back to the arcade. [MUSIC PLAYING]

33 thoughts on “Getting Started with Firebase for Unity – Firecasts

  1. Hey, this is exciting to see! I'm working on a calendar app in Unity, and wondering if it's possible to pull Calendar events from Google and Facebook through the Unity Firebase plugin?

  2. this is just get started, then what next. could you make basics tutorial how to code firebase in unity maybe auth, database, etc?

  3. How do i modify the build.gradle file in unity? i got gradle build failed when build the apk.

  4. I Finally realize FirebaseMessaging.unitypackage contains error. I follow step by step of this tutorial and import FirebaseMessaging instead of FirebaseAnalytics, the gradle build will failed if you going to build an apk file. Firebase please fix this issue and thankyou.

  5. um verdadeiro lixo não é como um encurtador do Google esse ae é muito difícil só aceita com celular

  6. My goodness that was easy! And agreed, a real-time database tutorial would be awesome! Thanks so much for this one!

  7. will this show user retention and session time?? is it done automatically or do i have to implement event logs in my every level?

  8. My Login Authentication is working fine in unity editor , but it is not working in Android device

    would you please help me why it is not working in my Android device

  9. I did everything but I don't see any events logged in the DebugView in the console. I think I have to run this command but not sure how:

    adb shell setprop debug.firebase.analytics.app <package_name>

  10. I need in one app, one button, when i press this button, it enable another button in another app. Example both app are open in 2 diferent cellphone. Then when i press the button in the fisrt app, in the other app appear one button, then when i press that button. the button from my app disapear.

    How can i do that, is possible?

  11. I have just completed Google LogIn in Unity By Using Firebase . It was too difficult to just follow Docs. Any how Finally I did.

Leave a Reply

Your email address will not be published. Required fields are marked *