---
source_url: https://www.pubnub.com/docs/sdks/unreal
title: Unreal API & SDK Docs 2.0.5
updated_at: 2026-06-04T11:13:23.569Z
sdk_name: PubNub Unreal SDK
sdk_version: 2.0.5
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Unreal API & SDK Docs 2.0.5

PubNub Unreal SDK, use the latest version: 2.0.5

This guide walks you through a simple "Hello, World" application that demonstrates the core concepts of PubNub in Unreal Engine:

* Setting up a connection to PubNub
* Sending a "Hello, World" message
* Receiving messages in real-time

## Overview

This guide will help you get up and running with PubNub in your Unreal Engine application using C++ programming. You'll learn how to initialize the SDK, set up event listeners, and send/receive a simple "Hello, World" message - all with minimal code.

## Prerequisites

Before we dive in, make sure you have:

* A basic understanding of Unreal Engine and C++
* Unreal Engine installed (version 5.2 or higher recommended)
* A PubNub account (we'll help you set this up!)

##### Installation on Unreal Engine <5.2.0

For Unreal Engine versions lower than 5.2.0 (5.0.X - 5.1.X), you have to download the plugin manually.

1. Download and install Unreal Engine version 5.0.X or 5.1.X.
2. Create a new blank Unreal project in a location of your choice.
3. Create an empty Plugins folder in your Unreal project's location.

#### Download the SDK

In the `Plugins` folder of your Unreal project:

1. Clone the content of the Unreal SDK repository: https://github.com/pubnub/unreal-engine.
2. Change the folder name in which you cloned the content to Pubnub.

#### Configure the workspace

1. In the project's root folder, right-click the projectname.uproject file and, depending on your operating system (OS), select: OSSelectionMacOSServices -> Generate xCode projectWindowsGenerate Visual Studio project files
2. Wait until the files are generated and open your OS-specific workspace.
3. In your IDE, navigate to Source/_{YourProject}_/_{YourProject}_.Build.cs and add a dependency to PubnubLibrary. PrivateDependencyModuleNames.AddRange(new string[] { "PubnubLibrary" });
4. Compile the code and run the project.

## Setup

### Get your PubNub keys

First things first – you'll need your PubNub keys to get started. Here's how to get them:

* [Sign in](https://admin.pubnub.com/#/login) or [create an account](https://admin.pubnub.com/#/signup) on the Admin Portal and create an app.
* When you create a new app, the first set of keys is generated automatically.
* Find your publish and subscribe keys in the app dashboard.

We recommend that you create separate keysets for [production and test environments](https://www.pubnub.com/docs/general/setup/account-setup#environment-aligned-keys).

### Install the SDK

:::note SDK version
Always use the latest SDK version to have access to the newest features and avoid security vulnerabilities, bugs, and performance issues.
:::

The PubNub Unreal Engine SDK is available on [FAB](https://www.fab.com/listings/9501a8d6-f9e6-4cf8-8b56-d173bdb71fc4) as part of the **PubNub Gaming SDK** - a free downloadable plugin that you can add to your project. You can also get the plugin directly from [GitHub](https://github.com/pubnub/unreal-engine).

1. Install the PubNub Gaming SDK plugin from FAB. For information on installing plugins, refer to the Unreal Engine documentation.
2. Enable the PubNubSDK in your project. For information on enabling plugins, refer to the Unreal Engine documentation.
3. In your project's Build.cs file, add the dependency (this is required only for using PubNub SDK with C++): PrivateDependencyModuleNames.AddRange(new string[] { "PubnubLibrary" });
4. In files that you want to use PubNub SDK functionality include the necessary header: #include "PubnubSubsystem.h"

### Configure PubNub in Unreal Editor

After installing the PubNub SDK plugin, you should configure it in the Unreal Editor's Project Settings:

1. In the Unreal Editor window, click the Settings dropdown and select Project Settings.
2. In the Project Settings window, scroll down to the Plugins section and click Pubnub SDK.
3. In the Plugins - Pubnub SDK view, provide the following configuration options: OptionValueNotesPublish KeydemoReplace with your key from the Admin Portal for productionSubscribe KeydemoReplace with your key from the Admin Portal for productionSecret Key(leave empty)Only required for access control operationsInitialize Automatically(checked)Recommended for easier setupSet Secret Key Automatically(unchecked)Only check if using access control

After configuring these settings, the PubNub SDK will be ready to use in your project.

:::warning SDK initialization
If you choose not to enable **Initialize Automatically**, you'll need to manually initialize the PubNub SDK in your code before using any PubNub functionality.
:::

:::note Required User ID
Always set the User ID to uniquely identify the user or device that connects to PubNub. This User ID should be persisted, and should remain unchanged for the lifetime of the user or the device. If you don't set the User ID, you won't be able to connect to PubNub.
:::

### Configure the Unreal Engine project

For our simple "Hello, World" example, we'll focus on creating just two essential classes:

1. **GameInstance** to initialize PubNub and handle messages.
2. **PlayerController** to trigger sending our "Hello, World" message with a key press.

#### Create a new project

Launch the Unreal Editor and create a new C++ project (or open your existing project).

#### Create essential C++ classes

Create the following C++ classes through the editor:

1. Click the **Tools** dropdown menu and select **New C++ Class...** or simply **Select Tools** -> **New C++ Class...**.
2. Create these classes:

* `PubNubGameInstance` - Inherit from UGameInstance
* `PubNubPlayerController` - Inherit from APlayerController

#### Configure project settings

Configure the project settings:

1. Navigate to Edit > Project Settings.
2. Under Maps & Modes:

* Set Default GameInstance to your PubNubGameInstance class.
* Set Default Player Controller to your PubNubPlayerController class.

## Steps

### Initialize PubNub

#### Blueprint

#### C++

First, we'll set up the PubNub GameInstance class to initialize the PubNub SDK and handle messages.

Make sure to replace the demo keys with your app's publish and subscribe keys from the Admin Portal.

In your header file (PubNubGameInstance.h):

```cpp
// PubNubGameInstance.h
#pragma once

#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "PubnubSubsystem.h"
#include "PubNubGameInstance.generated.h"

UCLASS()
//Replace YOUR_PROJECT_API with [Project_Name]_API
class YOUR_PROJECT_API UPubNubGameInstance : public UGameInstance
{
	GENERATED_BODY()
    
public:
	virtual void Init() override;
    
	// Message listener
	UFUNCTION()
	void OnMessageReceived(FPubnubMessageData MessageData);
    
	// Error handler
	UFUNCTION()
	void OnErrorReceived(FString ErrorMessage, EPubnubErrorType ErrorType);
    
	// Function to publish our Hello World message
	void PublishHelloWorld();
    
private:
	UPubnubSubsystem* PubnubSubsystem = nullptr;
	FString ChannelName;
};
```

In your implementation file (PubNubGameInstance.cpp):

```cpp
// PubNubGameInstance.cpp
#include "PubNubGameInstance.h"

void UPubNubGameInstance::Init()
{
	Super::Init();
    
	// Set the channel we'll use for our Hello World example
	ChannelName = "hello_world_channel";
    
	// Get the PubNub subsystem
	PubnubSubsystem = GetSubsystem<UPubnubSubsystem>();
    
	// Set User ID - required for connection
	PubnubSubsystem->SetUserID("unreal_user_123");
    
	// Bind message and error handlers
	PubnubSubsystem->OnMessageReceived.AddDynamic(this, &UPubNubGameInstance::OnMessageReceived);
	PubnubSubsystem->OnPubnubError.AddDynamic(this, &UPubNubGameInstance::OnErrorReceived);
    
	// Subscribe to our channel
	PubnubSubsystem->SubscribeToChannel(ChannelName);
    
	UE_LOG(LogTemp, Log, TEXT("PubNub initialized and subscribed to channel: %s"), *ChannelName);
	UE_LOG(LogTemp, Log, TEXT("Press P key to publish a Hello World message"));
	
}

void UPubNubGameInstance::OnMessageReceived(FPubnubMessageData MessageData)
{
	// When a message is received, log it to the console
	UE_LOG(LogTemp, Log, TEXT("Message received on channel: %s"), *MessageData.Channel);
	UE_LOG(LogTemp, Log, TEXT("Message content: %s"), *MessageData.Message);
}

void UPubNubGameInstance::OnErrorReceived(FString ErrorMessage, EPubnubErrorType ErrorType)
{
	// Log any errors
	UE_LOG(LogTemp, Error, TEXT("PubNub error: %s"), *ErrorMessage);
}

void UPubNubGameInstance::PublishHelloWorld()
{
	// Our simple Hello World message (with quotes as it has to be a valid Json)
	FString Message = "\"Hello, World!\"";
    
	UE_LOG(LogTemp, Log, TEXT("Publishing message: %s"), *Message);
    
	// Publish to our channel
	PubnubSubsystem->PublishMessage(ChannelName, Message);
}
```

For more information, refer to the [Configuration](https://www.pubnub.com/docs/sdks/unreal/api-reference/configuration) section of the SDK documentation.

### Set up event listeners

Listeners help your app react to events and messages. You can implement custom app logic to respond to each type of message or event.

We've already set up our message and error listeners in the GameInstance's Init method. The listeners will:

* Log any received messages to the Output Log.
* Log any errors that occur.

For more information, refer to the [Event Listeners](https://www.pubnub.com/docs/sdks/unreal/api-reference/configuration#event-listeners) section of the SDK documentation.

### Create a subscription

To receive messages sent to a particular channel, you need to subscribe to it.

We've already subscribed to the "hello_world_channel" in our GameInstance's Init method.

For more information, refer to the [Subscribe](https://www.pubnub.com/docs/sdks/unreal/api-reference/publish-and-subscribe#subscribe) section of the SDK documentation.

### Publish messages

When you publish a message to a channel, PubNub delivers that message to everyone who is subscribed to that channel.

A message can be any type of JavaScript Object Notation (JSON)-serializable data (such as objects, arrays, integers, strings) that is smaller than 32 KiB.

#### Blueprint

#### C++

Let's create a PlayerController that will publish a "Hello, World!" message when the P key is pressed.

In your header file (PubNubPlayerController.h):

```cpp
// PubNubPlayerController.h
#pragma once

#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "PubNubGameInstance.h"
#include "PubNubPlayerController.generated.h"

UCLASS()
//Replace YOUR_PROJECT_API with [Project_Name]_API
class YOUR_PROJECT_API APubNubPlayerController : public APlayerController
{
	GENERATED_BODY()
    
protected:
	virtual void SetupInputComponent() override;
    
	// Handler for the P key press
	void HandleKeyP();
    
	// Reference to our game instance
	UPubNubGameInstance* PubNubInstance = nullptr;
};
```

In your implementation file (PubNubPlayerController.cpp):

```cpp
// PubNubPlayerController.cpp
#include "PubNubPlayerController.h"
#include "Kismet/GameplayStatics.h"

void APubNubPlayerController::SetupInputComponent()
{
	Super::SetupInputComponent();
    
	// Bind the P key to publish a Hello World message
	InputComponent->BindKey(EKeys::P, IE_Pressed, this, &APubNubPlayerController::HandleKeyP);
    
	// Get our game instance
	PubNubInstance = Cast<UPubNubGameInstance>(UGameplayStatics::GetGameInstance(GetWorld()));
}

void APubNubPlayerController::HandleKeyP()
{
	if (PubNubInstance)
	{
		PubNubInstance->PublishHelloWorld();
	}
}
```

For more information, refer to the [Publish](https://www.pubnub.com/docs/sdks/unreal/api-reference/publish-and-subscribe#publish) section of the SDK documentation.

### Run the app

To test your Hello World PubNub integration:

1. In the Unreal Editor, click the **Play** button in the toolbar.
2. Look at the Output Log (Window > Developer Tools > Output Log).
3. You should see initialization messages confirming that PubNub is connected and subscribed.
4. Press the P key to publish a "Hello, World!" message.
5. In the Output Log, you should see both the publish confirmation and the received message.

#### Cross-platform testing

To verify that your PubNub implementation works across platforms:

1. Open the [PubNub Debug Console](https://www.pubnub.com/docs/console/) in your web browser.
2. Enter the demo publish and subscribe keys.
3. Subscribe to "hello_world_channel".
4. Press the P key in your Unreal application to send a message.
5. The message should appear in both your Unreal app's logs and the PubNub Debug Console.
6. You can also publish a message from the Debug Console and see it appear in your Unreal app's logs.

## Complete example

* PubNubGameInstance.h

```cpp
// PubNubGameInstance.h
#pragma once

#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "PubnubSubsystem.h"
#include "PubNubGameInstance.generated.h"

UCLASS()
//Replace YOUR_PROJECT_API with [Project_Name]_API
class YOUR_PROJECT_API UPubNubGameInstance : public UGameInstance
{
	GENERATED_BODY()
    
public:
	virtual void Init() override;
    
	// Message listener
	UFUNCTION()
	void OnMessageReceived(FPubnubMessageData MessageData);
    
	// Error handler
	UFUNCTION()
	void OnErrorReceived(FString ErrorMessage, EPubnubErrorType ErrorType);
    
	// Function to publish our Hello World message
	void PublishHelloWorld();
    
private:
	UPubnubSubsystem* PubnubSubsystem = nullptr;
	FString ChannelName;
};
```

* PubNubGameInstance.cpp

```cpp
// PubNubGameInstance.cpp
#include "PubNubGameInstance.h"

void UPubNubGameInstance::Init()
{
	Super::Init();
    
	// Set the channel we'll use for our Hello World example
	ChannelName = "hello_world_channel";
    
	// Get the PubNub subsystem
	PubnubSubsystem = GetSubsystem<UPubnubSubsystem>();
    
	// Set User ID - required for connection
	PubnubSubsystem->SetUserID("unreal_user_123");
    
	// Bind message and error handlers
	PubnubSubsystem->OnMessageReceived.AddDynamic(this, &UPubNubGameInstance::OnMessageReceived);
	PubnubSubsystem->OnPubnubError.AddDynamic(this, &UPubNubGameInstance::OnErrorReceived);
    
	// Subscribe to our channel
	PubnubSubsystem->SubscribeToChannel(ChannelName);
    
	UE_LOG(LogTemp, Log, TEXT("PubNub initialized and subscribed to channel: %s"), *ChannelName);
	UE_LOG(LogTemp, Log, TEXT("Press P key to publish a Hello World message"));
	
}

void UPubNubGameInstance::OnMessageReceived(FPubnubMessageData MessageData)
{
	// When a message is received, log it to the console
	UE_LOG(LogTemp, Log, TEXT("Message received on channel: %s"), *MessageData.Channel);
	UE_LOG(LogTemp, Log, TEXT("Message content: %s"), *MessageData.Message);
}

void UPubNubGameInstance::OnErrorReceived(FString ErrorMessage, EPubnubErrorType ErrorType)
{
	// Log any errors
	UE_LOG(LogTemp, Error, TEXT("PubNub error: %s"), *ErrorMessage);
}

void UPubNubGameInstance::PublishHelloWorld()
{
	// Our simple Hello World message (with quotes as it has to be a valid Json)
	FString Message = "\"Hello, World!\"";
    
	UE_LOG(LogTemp, Log, TEXT("Publishing message: %s"), *Message);
    
	// Publish to our channel
	PubnubSubsystem->PublishMessage(ChannelName, Message);
}
```

* PubNubPlayerController.h

```cpp
// PubNubPlayerController.h
#pragma once

#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "PubNubGameInstance.h"
#include "PubNubPlayerController.generated.h"

UCLASS()
//Replace YOUR_PROJECT_API with [Project_Name]_API
class YOUR_PROJECT_API APubNubPlayerController : public APlayerController
{
	GENERATED_BODY()
    
protected:
	virtual void SetupInputComponent() override;
    
	// Handler for the P key press
	void HandleKeyP();
    
	// Reference to our game instance
	UPubNubGameInstance* PubNubInstance = nullptr;
};
```

* PubNubPlayerController.cpp

```cpp
// PubNubPlayerController.cpp
#include "PubNubPlayerController.h"
#include "Kismet/GameplayStatics.h"

void APubNubPlayerController::SetupInputComponent()
{
	Super::SetupInputComponent();
    
	// Bind the P key to publish a Hello World message
	InputComponent->BindKey(EKeys::P, IE_Pressed, this, &APubNubPlayerController::HandleKeyP);
    
	// Get our game instance
	PubNubInstance = Cast<UPubNubGameInstance>(UGameplayStatics::GetGameInstance(GetWorld()));
}

void APubNubPlayerController::HandleKeyP()
{
	if (PubNubInstance)
	{
		PubNubInstance->PublishHelloWorld();
	}
}
```

## Next steps

Great job! 🎉 You've successfully created your first PubNub application in Unreal Engine. Here are some exciting things you can explore next:

### Build chat

* Learn about the [Unreal Chat SDK](https://www.pubnub.com/docs/chat/unreal-chat-sdk) for ready-to-use chat features.
* Implement user [Presence](https://www.pubnub.com/docs/sdks/unreal/api-reference/presence) to show who's online.

### Advanced features

* Try out [Presence](https://www.pubnub.com/docs/sdks/unreal/api-reference/presence) to track online/offline status.
* Implement [Message Persistence](https://www.pubnub.com/docs/sdks/unreal/api-reference/storage-and-playback) to store and retrieve messages.
* Use [Access Manager](https://www.pubnub.com/docs/sdks/unreal/api-reference/access-manager) to secure your channels.
* Implement [Objects](https://www.pubnub.com/docs/sdks/unreal/api-reference/objects) to manage users and channels metadata.

### Real examples

* Look at the [Announcing PubNub's UE and Gaming Chat SDKs](https://www.pubnub.com/blog/announcing-pubnubs-unreal-engine-and-gaming-chat-sdks/) blog.
* Explore our [GitHub repository](https://github.com/pubnub/unreal-engine/) for more code samples.

### More help

* Check out our [SDK reference documentation](https://www.pubnub.com/docs/sdks/unreal/api-reference/configuration) for detailed API information.
* Visit our [support portal](https://support.pubnub.com/) for additional resources.
* Ask our AI assistant (the looking glass icon at the top of the page) for help.

## Terms in this document

* **Publish Key** - A unique identifier that allows your application to send messages to PubNub channels. It's part of your app's credentials and should be kept secure.
* **PubNub** - PubNub is a real-time messaging platform that provides APIs and SDKs for building scalable applications. It handles the complex infrastructure of real-time communication, including: Message delivery and persistence, Presence detection, Access control, Push notifications, File sharing, Serverless processing with Functions and Events & Actions, Analytics and monitoring with BizOps Workspace, AI-powered insights with Illuminate.
* **Subscribe Key** - A unique identifier that allows your application to receive messages from PubNub channels. It's part of your app's credentials and should be kept secure.