Unreal Engine

Learn how to use Stash's Unreal SDK for Unreal Engine 5

🚧

The Unreal SDK is in beta. Please contact us to get access.

This guide explains how to integrate Apple and Google account linking into your Unreal Engine 5 project using Stash's SDK. This integration allows players to sign in and link their Apple and Google accounts for authentication within your Unreal Engine application.

Prerequisites

Before you begin, make sure you:

  • Install Unreal Engine 5.
  • Have an Apple Developer Account for setting up sign in with Apple.
  • Have access to the Google Developer Console for configuring Google Sign-In.
  • Have basic knowledge of Unreal Engine 5 and C++/Blueprint scripting.

1. Set up your Unreal Project

Install the Stash Unreal SDK. Ensure the SDK is linked correctly by testing it with an API call, or verifying the SDK initialization. Then, navigate to Edit > Project Settings in Unreal Engine and configure the following project settings.

  1. Navigate to Platforms > iOS and Platforms > Android to configure the necessary settings for Apple and Google Sign-In respectively.
  2. Ensure that your project has the correct Bundle Identifier (iOS) and Package Name (Android).

2. Set up sign in with Apple

First, create an App ID in your Apple Developer account:

  1. Log in to your Apple Developer account.
  2. Navigate to Certificates, Identifiers & Profiles.
  3. Create an App ID and enable the Sign In with Apple capability.

Then, create a Service ID and configure the redirect URL:

  1. Create a Service ID under Identifiers.
  2. Enable Sign In with Apple for this Service ID.
  3. Add your app’s redirect URL under the Service ID configuration.

Generate and download an Apple Authentication Key with Sign In with Apple enabled, and then configure your Unreal project:

  1. In Project Settings, under Platforms > iOS, enable Sign In with Apple.
  2. Ensure the correct Entitlements file is linked to your project.

You can now use Stash SDK methods to initiate and handle the sign in process.

// Include the Stash SDK header
#include "StashSDK.h"

void MyGameInstance::SignInWithApple()
{
    UStashSDK::SignInWithApple(FOnStashSignInCompleted::CreateUObject(this, &MyGameInstance::OnAppleSignInCompleted));
}

void MyGameInstance::OnAppleSignInCompleted(bool bSuccess, const FString& ErrorMessage)
{
    if (bSuccess)
    {
        // Handle successful sign-in
    }
    else
    {
        // Handle sign-in failure
    }
}

Ensure the sign in with Apple button is appropriately styled and placed within your UI.

3. Set Up Google Sign-In

Start by creating a project in your Google Developer Console. Then, configure the OAuth Consent Screen under APIs & Services with the necessary details. Make sure to enable the Google Sign-In API for the project, and then create OAuth client IDs:

  1. Create an OAuth 2.0 Client ID for both iOS and Android.
  2. Add the necessary redirect URIs.

Within your Unreal project, ensure the required permissions for Google Sign-In are added to Project Settings under Platforms > Android.

You can now use Stash SDK methods to initiate and handle the sign in process.

// Include the Stash SDK header
#include "StashSDK.h"

void MyGameInstance::SignInWithGoogle()
{
    UStashSDK::SignInWithGoogle(FOnStashSignInCompleted::CreateUObject(this, &MyGameInstance::OnGoogleSignInCompleted));
}

void MyGameInstance::OnGoogleSignInCompleted(bool bSuccess, const FString& ErrorMessage)
{
    if (bSuccess)
    {
        // Handle successful sign-in
    }
    else
    {
        // Handle sign-in failure
    }
}

Ensure the Google Sign-In button is appropriately styled and placed within your UI.

4. Handle account linking

After players are authenticated, use the Stash SDK to link their accounts with their game profile.

void MyGameInstance::LinkAccount(const FString& Provider)
{
    UStashSDK::LinkAccount(Provider, FOnStashAccountLinkCompleted::CreateUObject(this, &MyGameInstance::OnAccountLinkCompleted));
}

void MyGameInstance::OnAccountLinkCompleted(bool bSuccess, const FString& ErrorMessage)
{
    if (bSuccess)
    {
        // Handle successful account linking
    }
    else
    {
        // Handle account linking failure
    }
}

📘

Multiple linked accounts

Some players might want to link both their Apple and Google accounts. Make sure your game and UI can handle these scenarios.

5. Test your integration

Test the integration on both iOS and Android platforms, and make sure the account linking flows work as expected. You might need to use the logging and debugging tools provided by the Unreal Engine and the Stash SDK to troubleshoot any issues.