Skip to content

Authentication Examples

This section demonstrates the most common and practical usage patterns of Firebase Authentication in Unreal Engine projects.

Firebase Authentication is used to create and manage a user identity that can be shared across other Firebase services such as Realtime Database, Firestore, and Cloud Storage.

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


Initializing Authentication

Before using any authentication features, the Authentication module must be initialized.

Initialization should be performed once, typically during game startup, after Firebase itself has been successfully initialized.

Without this step, all authentication operations will fail.


Anonymous Sign-In

Anonymous sign-in is the most common authentication method for mobile games.

It allows a user to be authenticated without providing any credentials, while still receiving a unique and persistent user ID.

This approach is ideal for:

  • instant access without login screens
  • guest users
  • saving progress automatically
  • upgrading to a permanent account later

When anonymous sign-in succeeds:

  • a unique user ID (UID) is created
  • the user remains signed in across app restarts
  • the UID can be immediately used with other Firebase services

If sign-in fails, the failure callback can be used to handle network or configuration errors.


Other Sign-In Methods

Firebase Authentication also supports additional sign-in methods.

Google Sign-In

Google Sign-In allows users to authenticate using their Google account.
This method requires additional configuration in the Firebase Console and is typically used for permanent accounts.

Email and Password

Email-based authentication supports:

  • creating new users
  • signing in with email and password
  • sending password reset emails
  • email verification

These methods are suitable for projects that require traditional account systems.


Checking Authentication State and User Data

After a successful sign-in, it is common to immediately read basic information about the authenticated user and store it in game state or UI variables.

Typical usage pattern:

  • retrieve the current user ID
  • retrieve available profile information (display name, email)
  • store these values for later use in gameplay logic or UI

Common use cases include:

  • identifying the player in backend systems
  • associating save data with a specific user
  • displaying account information in profile screens

Important notes:

  • user data getters return values for the currently authenticated user
  • some fields (such as display name or email) may be empty depending on the sign-in method
  • getters are safe to call after a successful authentication flow

This pattern is commonly used right after sign-in or during game startup to initialize user-related state without making additional network requests.


Signing Out

Signing out removes the current authentication session from the device.

After signing out, it is important to explicitly reset all user-related state inside the game, since Firebase no longer considers the user authenticated.

Typical actions performed after sign-out:

  • clear stored user ID
  • clear cached profile data (display name, email)
  • reset UI elements that depend on authentication state
  • optionally redirect the player to a login or start screen

Important notes:

  • after sign-out, all authentication getters return empty or invalid values
  • any features that rely on authentication should be disabled until a new sign-in occurs
  • sign-out does not delete the user account, it only removes the local session

This pattern is commonly used for explicit logout flows or account switching scenarios, ensuring that no stale user data remains active after the session ends.


Summary

Firebase Authentication provides a flexible and reliable way to manage user identity in Unreal Engine projects.

By using anonymous sign-in as a default entry point and adding optional authentication methods when needed, you can support both casual and persistent user experiences while keeping authentication logic simple and scalable.