Skip to content

Cloud Messaging Examples

Firebase Cloud Messaging is most commonly used to subscribe users to topics and deliver push notifications sent from the Firebase Console. For basic notification workflows, manual token handling or advanced message processing is usually not required.

After subscribing to a topic, notifications will be delivered even if the application is closed or the device is locked.

  • When the game is not running or in the background, notifications are shown by the operating system as standard system notifications.
  • When the game is running in the foreground, system notifications are not displayed automatically. In this case, messages can be received in-game using Listen Cloud Messaging and handled manually (for example, by showing a custom popup or updating UI).

All examples below are shown using Blueprint nodes. Firebase is assumed to be already initialized.


Subscribing to a Topic

The most common Cloud Messaging use case is subscribing a user to one or more topics. Once subscribed, the user will receive all notifications sent to that topic from the Firebase Console or backend services.

Topic subscriptions are usually performed:

  • on first application launch
  • after user login or profile creation
  • after the user agrees to receive notifications

Example: Subscribing to a Global Topic

In this example, the user is subscribed to multiple Cloud Messaging topics based on their account state.

First, the user is always subscribed to a general global topic. This topic is typically used for announcements, maintenance notices, or other notifications intended for all users.

Then, an additional conditional subscription is performed. If the user has a premium account (IsPremium is true), they are also subscribed to a premium topic. This allows you to send targeted notifications only to premium users, such as exclusive offers, bonuses, or feature announcements.

This pattern enables flexible and scalable notification targeting:

  • global topics for messages sent to all users
  • additional topics for specific user segments (for example, premium users)

If a subscription succeeds, the user will start receiving notifications sent to that topic.
If a subscription fails, the failure callback can be used to log the error or retry the operation.

Using topic-based subscriptions like this avoids the need for manual token management and keeps notification logic simple and maintainable.


Requesting Notification Permission (Android 13+)

On Android 13 and higher (API level 33+), push notifications require explicit user permission.
Without this permission, notifications will not be displayed, even if Cloud Messaging is correctly configured.

This permission is not handled by Firebase and must be requested using Unreal Engine’s built-in Android permission system.

Required Permission: android.permission.POST_NOTIFICATIONS

Use the standard Unreal Engine Blueprint node Request Android Permissions to request this permission before subscribing the user to a topic.

It is recommended to request notification permission:

  • on first launch
  • or before subscribing the user to Cloud Messaging topics

Additional Notes

  • Cloud Messaging tokens are generated automatically by Firebase and are used internally for message delivery
  • Automatic Cloud Messaging initialization is enabled by default and does not require manual configuration in most projects
  • Listening for incoming Cloud Messaging messages is only required when handling custom data messages or advanced workflows

For most projects, subscribing users to topics and requesting notification permission is sufficient to enable push notifications.


Summary

Firebase Cloud Messaging provides a simple and reliable way to deliver push notifications to your users.

By subscribing users to topics and ensuring notification permission is granted on modern Android versions, you can deliver announcements and updates without additional backend complexity.