Firebase Unity3D example: a walk through tutorial

16 Jan


Step I: Download Firebase Unity3D packages

  1. Download Firebase Unity SDK.
  2. Create a Unity3D project.
  3. Unpack the file, there will be a number of different unity packages. Double click on the packages you wish to add (i.e. import) to Unity3D projects. In this article, I am using FirebaseMessaging as an example.


  4. Once the packages of interest are imported to Unity3D, you will see several folders created in your project:


Step II: setup in Firebase Console

  1. Create a Firebase project in the Firebase console. If you already have an existing Google project associated with your mobile app, click Import Google Project.


  2. Click Add Firebase to your Android/iOS app and follow the setup steps.

     image image

    When prompted, enter your app’s bundle ID. It’s important to enter and remember the bundle ID.

  3. If you’re importing an existing project, this may happen automatically and you can just download the config file. The file for Unity3D might be one or both of the below files:
        GoogleService-Info.plist (for iOS)
        Google-services.json (for Android).

  4. Add the GoogleService-Info.plist (for iOS) and/or Google-services.json (for Android) file to the project by dragging the downloaded file(s) from the Firebase console into any folder in the Unity project.

Step III: Add code to your project

  1. Create a MonoBehaviour script .

    public class GameInit : MonoBehaviour
        public void Start()
            Debug.Log(Unity Firebase App started);
            Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
            Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;

        public void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token)
            Debug.Log(Received Registration Token: + token.Token);

        public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e)
            Debug.Log(Received a new message from: + e.Message.From);

  2. Attach the script to the camera or which ever game object.

Step IV: Build and run the project

  1. Setup the App’s bundle ID, this should be the same when you create the Firebase project in Firebase console.


  2. Build for iOS in Unity3D and attach it to the scene

    • 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.
  3. 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.

Now, everything should be fine and you can run the app on your Android and iOS devices without problems.

Step V: Testing

  1. Now go to Firebase console. Select your project.
  2. Select Notification on the left navigation bar, and then click “New Message” button


  3. Send some message, and note the Unity3D app running on your device!


  4. Now you should see below notification on your Android or iOS device!


Enjoy and happy coding!


Posted by on January 16, 2017 in Programming, Unity 3d


Tags: , , , , , , , ,

8 responses to “Firebase Unity3D example: a walk through tutorial

  1. afra

    February 18, 2017 at 3:03 pm

    thank you

  2. Ranadheer

    May 11, 2017 at 9:35 pm

    Getting below logs but Notification not getting displayed in the device. can you please help.

    05-11 19:02:00.814 7763-7784/? I/Unity: Received a new message from:
    (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)

  3. bedo

    October 5, 2017 at 12:07 pm

    thank you so much!

  4. özay duman (garfmedya)

    January 25, 2018 at 1:56 am

    Thank you so much, i could add remote notification easily with this tutorial.

  5. Waqas Ahmed

    May 3, 2018 at 11:12 pm

    notification not shown.

  6. xinyustudio

    May 14, 2018 at 9:08 am

    @Ahmed, you should try the app on device, rather than in the Unity Editor.

  7. Elvis Hrdz

    October 11, 2018 at 4:04 am

    its working, but theres options in firebase console so you can send key/values pairs. How can you get those values in OnMessageReceived method?

  8. IM

    July 3, 2019 at 5:55 pm

    If I want to get all the notifications from firebase to my unity app, how can I do it?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: