Last Updated: 8/16/2021, 3:07:05 AM

# UE4 SDK Getting Started

# Overview

You can use the AccelByte UE4 SDK to help implement our back end services in your game. The SDK acts as a bridge between your game and our services, making those services easy to access. Follow the tutorials below to learn how to set up our UE4 SDK.

# Prerequisites

# Integrate the AccelByte UE4 SDK Plugin into Your Game

To integrate the UE4 SDK plugin into your game, follow the steps below:

  1. Create a new Unreal Engine 4 project, or open an existing one.

    ue4-gsg

  2. If you are using Blueprint for your project, you should create a new C++ class first so that you can generate files with Visual Studio. If your project is in C++, you can skip this step.

    ue4-gsg

  3. Copy the Plugins/AccelByteUe4Sdk folder from the AccelByte UE4 SDK you just downloaded and paste it into [yourprojectpath]/Plugins.

  4. In your project directory, right-click your UE4 project and click Generate Visual Studio project files.

    ue4-gsg

  5. Open your Visual Studio project that was generated in the previous step.

    ue4-gsg

  6. In Visual Studio, build Your Project Solution by pressing Ctrl + Shift + B on your keyboard, or build only your project by right-clicking on the game project and clicking Build.

    ue4-gsg

  7. After your build is done, open the UE4 editor and go to the Plugins window. Ensure that the AccelByte Plugin checkbox is selected in the **Project Plugin **section.

    ue4-gsg

  8. To use the plugin in C++ you must include the Accelbyte SDK in the project’s Target script:

    • In /MyAwesomeGame.uproject

      "Plugins": [
      ...
      {
          "Name": "AccelByteUe4Sdk",
          "Enabled": true
      },
      ...
      
    • In /Source/MyAwesomeGame.Target.cs, and in /Source/MyAwesomeGameEditor.Target.cs, add the following:

      ExtraModuleNames.AddRange(new string[]
      {
          ...
          "AccelByteUe4Sdk",
          ...
      }
      
    • In /Source/MyAwesomeGame/MyAwesomeGame.Build.cs, add the following:

      PublicDependencyModuleNames.AddRange(
                  new string[] {
                      ...
                      "AccelByteUe4Sdk",
                      ...
                  }
      
    • Developers can also edit the configuration manually via text editor. The configuration is stored under [ProjectPath]/Config/DefaultEngine.ini. In the .ini file, fill in the fields below with the data from the game client credentials you created in the Admin Portal.

      [/Script/AccelByteUe4Sdk.AccelByteServerSettings]
      ClientId=Game Server Client ID
      ClientSecret=Game Server Client Secret
      Namespace=Game Namespace
      PublisherNamespace=Publisher Namespace
      RedirectURI="http://127.0.0.1"
      BaseUrl="https://demo.accelbyte.io"
      NonApiBaseUrl="https://demo.accelbyte.io"
      
      [/Script/AccelByteUe4Sdk.AccelByteSettings]
      ClientId=Game Client ID
      ClientSecret=Game Client Secret
      Namespace=Game Namespace
      PublisherNamespace=Publisher Namespace
      
    • You can also configure the plugin in the Editor by clicking Edit on the menu par and selecting Project Settings. Then, scroll down to the AccelByte SDK category to fill in your game client credentials. Only the fields found in the .ini file. The rest of the fields here can be left blank in most cases. For more information, check out our Clients documentation.

      ue4-gsg

# Plugin Usage (C++)

There are two ways to use our SDK plugin, either with C++ or Blueprint. In this example, we will integrate the Login feature from our SDK, using C++.

Here’s an example of how to use the plugin as a C++ Blueprint Library:

  1. In the UE4 Editor, create a C++ Blueprint Function Library.

    ue4-gsg

  2. Here is the code for the MyBPFLibrary.h header:

    #pragma once
    
    #include "CoreMinimal.h"
    #include "Kismet/BlueprintFunctionLibrary.h"
    #include "MyBPFLibrary.generated.h"
    
    /**
     * My Blueprint Function Library
     */
    
    UCLASS()
    class MYAWESOMEGAME_API UMyBPFLibrary : public UBlueprintFunctionLibrary
    {
    	GENERATED_BODY()
    
    public:
    
    	UFUNCTION(BlueprintCallable)
    	static void LoginWithUsername(FString UserName, FString Password);
    
    };
    
  3. Here is the code for the MyBPFLibrary.cpp implementation:

    #include "MyBPFLibrary.h"
    #include "Core/AccelByteRegistry.h"
    #include "Api/AccelByteUserApi.h"
    #include "Api/AccelByteUserProfileApi.h"
    #include "Core/AccelByteError.h"
    #include "Models/AccelByteUserProfileModels.h"
    
    using AccelByte::THandler;
    using AccelByte::FErrorHandler;
    
    void UMyBPFLibrary::LoginWithUsername(FString UserName, FString Password)
    {
    	auto OnSuccess = FVoidHandler::CreateLambda([]()
    		{
    			UE_LOG(LogTemp, Log, TEXT("Login successful"));
    		});
    	auto OnFailed = FErrorHandler::CreateLambda(
    		[](int32 ErrorCode, const FString& ErrorMessage)
    		{
    			UE_LOG(LogTemp, Log, TEXT("Error. Code: %d, Reason: %s"), ErrorCode, *ErrorMessage);
    	});
    
    	AccelByte::FRegistry::User.LoginWithUsername(UserName, Password, OnSuccess, OnFailed);
    }
    
  4. On your existing game instance class, call out our test function, LoginWithUsername.

    #include "MyBPFLibrary.h"
    ...
    void UMyGameInstance::GameClientLogin()
    {
    ...
    	const FString OriginalEmail = TEXT("originalEmail@example.com");
    	const FString Password = TEXT("password");
    	UMyBPFLibrary::LoginWithUsername(OriginalEmail, Password);
    ...
    }
    
  5. You can also call the function from a blueprint. Here is the LoginWithUsername call from a level blueprint.

    ue4-gsg

# Plugin Usage (Blueprint)

Our SDK plugin also supports Blueprint as well. It’s possible to use the plugin in full Blueprint, although some functionality is still C++ only. In this tutorial, we will demo how to use the Login API. Here’s example of using the Blueprint API in a Level Blueprint:

  1. Open the Blueprint level in the UE4 editor.

    ue4-gsg

  2. Drag a node from the Begin Play event execution pin then release the mouse. Open the AccelByte menu, then open User, API, and select Login with Username.

    ue4-gsg

  3. The Login with Username node requires two inputs: username & password, and two event pins: On Success & On Error. These inputs are mandatory.

    ue4-gsg

  4. Drag the red event pins and release the mouse click. Select Add custom event in the Add event category to create a matching callback for the pin. Make sure to name the event appropriately.

    ue4-gsg

  5. Don’t forget to add functionality to the callbacks

    ue4-gsg

If the login process is successful, Callback Login Success will be triggered and Login Success should appear in the log and on screen. Otherwise, Callback Login Failed will be triggered and will appear along with the error code and message. Here, we use the Format Text node to concatenate the numeric code and message into a text object. Connect the Format Text node to the Print String node to display the formatted text on screen.

Our Blueprint graph looks like this:

ue4-gsg