A Beginner’s Guide to Integrating Push Notifications in Unity Projects

A Beginner’s Guide to Integrating Push Notifications in Unity Projects

This guide will walk you through the process of integrating Unity’s push notification service into your project. The steps are straightforward and easy to follow, making it beginner-friendly.


Before You Start:

  • Ensure that you open links in a new tab. You can do this by right-clicking on the link and selecting ‘Open link in new tab’, or by pressing the middle mouse button on it.
  • Please note that the interfaces of the websites may have changed, but the steps remain largely the same


Step 1: Set Up Your Unity Project Begin by creating a new Unity project or opening an existing one.

  • Ensure that the ‘Connect To Unity Cloud’ option is selected, and that your organization is correctly chosen.

Article content
Figure 1: Creating a new Unity project in Unity Hub.


Step 2: Install the Push Notifications Package From the Unity registry’s package manager, install the Push Notifications package.

  • If you don’t see the package, ensure you have enabled Pre-release packages in the ProjectSettings/PackageManager/Advanced settings.
  • Import the ‘Push Notifications Example’ script from the Samples, and then attach it to the game object present in the scene.

Article content
Figure 2: Installation of the Push Notifications Package and an Example Script from the Package Manager.


Step 3: Set Up Your Firebase Project Create a new project on Firebase or open an existing one. Open Firebase Console

Article content
Figure 3: Using the Firebase Home Screen to Create New Projects.

  • Register your Unity app on Firebase.

Article content
Figure 4: Registering an Android App on Firebase.


Step 4: Enable Authentication in Firebase This step is crucial as the Web API key won’t show up otherwise.

Article content
Figure 5: Firebase Authentication Page.


Step 5: Copy and Paste Keys Copy the Project ID, Project Number, Web API Key, and App ID from Firebase Project Settings, and paste them in your Unity project under Project Settings/Services/Push Notifications.

Figures 6, 7, 8: Copying Relevant Values from Firebase Project Settings and Pasting Them in Project Settings/Services/Push Notifications.

Article content
Figure 6
Article content
Figure 7
Article content
Figure 8


Step 6: Generate a New Private Key From the Service Accounts tab in your Firebase app project settings, generate a new private key.

Article content
Figure 9: Generating Private Key from Service Accounts Tab in Project Settings.


Step 7: Add the Google Key Navigate to Unity Cloud in Push Notifications settings and add the Google key. Open Unity Cloud

Article content
Figure 10: Adding the Downloaded Key in Settings/Google Key.


Step 8: Create a New Notification Go to the notifications tab and create a new notification. Fill in the details.

  • If the notifications tab does not open, enable VPN and try again.
  • Figures 11, 12: Creating a New Notification and Enabling VPN.

Article content
Figure 11
Article content
Figure 12


Step 9: Import In-Game Debug Console To test notifications instantly, import the In-Game Debug Console and drag the prefab into your scene. Asset Link

Article content
Figure 13: Importing In-Game Debug Console Asset to View Log Messages in the Builds.


Step 10: Make the Build and Copy the Device Token

  • You may encounter these errors. To resolve them, ensure that you set the ‘Target API Level’ in the player settings to 33, or to the level specified in the error messages.

Article content
Figure 14: Errors Encountered During the Build Process
Article content
Figure 15: Copying the Device Token in the Build Using the In-Game Debug Console.


Step 11: Test on Device In Unity Cloud, click ‘Test on Device’, paste the device token, and hit send. You should receive the notification.

  • Figures 16, 17: Pasting the Copied Device Token into the Android Device Token Field and Receiving a Push Notification on the Phone.

Article content
Figure 16
Article content
Figure 17


Step 12: Complete the Rest of the Settings Complete the rest of the settings by scheduling the notification.

Article content
Figure 18: The Push Notification Has Been Scheduled.



Congratulations, you have successfully integrated push notifications into your Unity project!

At present, this guide is exclusively for Android. However, I plan to create a version for iOS in the future.

If you encounter any issues or notice any mistakes in this article while following the steps, please leave a comment. I will assist you and make the necessary corrections to enhance this article and make it more beginner-friendly.


Video Tutorial:

https://youtu.be/i5-RRkLWFkQ?si=iEnGwQdOz46bhKgM

To view or add a comment, sign in

More articles by Adeel Bashir

Others also viewed

Explore content categories