Initial configuration
Before building your chat app, you must initialize and configure the Unreal Chat SDK.
Start by signing into the Admin Portal or creating an account if you don't have one yet.
Then, create an app on the Admin Portal. You will need a PubNub app to get a keyset that consists of a Subscribe Key and a Publish Key. These keys will let you establish a connection between PubNub and the chat app you're going to create with the Unreal Engine Chat SDK.
When you create a new app on the Admin Portal, the first set of demo keys is generated automatically, but a single app can have as many keysets as you like. We recommend that you create separate keysets for production and test environments.
Enable features on your keyset
Each keyset has its own configuration settings in the Admin Portal. To use some features in your chat app, you must enable appropriate settings on your app's keyset on the Admin Portal.
To use the Chat SDK, create or update users, track presence, and store messages in history, you must enable App Context, Presence, and Message Persistence.
Configure Unreal Engine
-
Download and install Unreal Engine version 5.0 or higher.
-
Create a new blank C++ Unreal project in a location of your choice.
Blueprint project package bug
If you decide to create a Blueprint project, you may run into a bug when you package your app. Refer to Package a Blueprint project for more information.
-
Create an empty
Plugins
folder in your Unreal project's location.
Download the SDK
In the Plugins
folder of your Unreal project:
-
Clone the content of the Unreal Engine Chat SDK repository: Unreal Engine Chat.
-
Change the folder name in which you cloned the content to
PubnubChatSDK
.
Configure the workspace
-
In the project's root folder, right-click the
projectname
.uproject
file and, depending on your operating system (OS), select:OS Selection MacOS Services -> Generate xCode project Windows Generate Visual Studio project files -
Wait until the files are generated and open your OS-specific workspace.
-
Navigate to
Source/_{YourProject}_/_{YourProject}_.Build.cs
and add a dependency toPubnubChatSDK
.PrivateDependencyModuleNames.AddRange(new string[] { "PubnubChatSDK" });
-
Compile the code and run the project.
Initialize PubNub
Once you have a PubNub account and an app created on the Admin Portal, you can start initializing PubNub Client API context and establish account-level credentials.
To initialize PubNub with the Unreal Chat SDK, use the Init Chat
method.
You must provide at least these three parameters: Publish Key
, Subscribe Key
, or User ID
. Apart from the required parameters, you can also configure additional options when initializing the Unreal Chat SDK. These options will let you add configuration required to implement advanced chat features, like typing indicator, user offline/online presence, push notifications, or client-side limiting that prevents spamming.
- Blueprint
- C++ / Input parameters
PubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
UPubnubChat* Chat = PubnubChatSubsystem->InitChat("Publish Key", "Subscribe Key", "User Id");
Input parameters
Parameter | Type | Required | Default | Feature | Description |
---|---|---|---|---|---|
Publish Key | String | Yes | n/a | Send messages | Specifies the key used to publish messages on a channel. |
Subscribe Key | String | Yes | n/a | Receive messages | Specifies the key used to subscribe to a channel. |
User Id | String | Yes | n/a | n/a | Unique User ID that becomes your app's current user. It's a string of up to 92 characters that identifies a single client (end user, device, or server) that connects to PubNub. Based on User ID, PubNub calculates pricing for your apps' usage. User ID should be persisted and remain unchanged. If you don't set userId , you won't be able to connect to PubNub. |
Config → Auth Key | String | No | n/a | Moderation | Specifies the key used to authorize operations in PubNub's Access Manager system. |
Config → Typing Timeout | Integer | No | 5000 | Typing Indicator | Specifies the default timeout after which the typing indicator automatically stops when no typing signals are received. The default and maximum value is set to 5000 milliseconds (5 seconds). |
Config → Typing Timeout Difference | Integer | No | 1000 | Typing Indicator | Specifies the difference in time between actually sending the typing indicator and the value of Typing Timeout . This is designed to cover for any network lag that may occur. If you set the Typing Timeout to 5 seconds and the Typing Timeout Difference to 1 second, the typing signal stops between the fourth and fifth second. The default value is set to 1000 milliseconds (1 second). |
Config → StoreUserActivityTypestamp | Bool | No | False | User's last online activity, global presence | Specifies if you want to track the user's global presence in your chat app. The user's activity is tracked through the LastActiveTimeStamp parameter on the User object. |
Config → StoreUserActivityInterval | Integer | No | 600000 | User's last online activity, global presence | Specifies how often the user global presence in the app should be updated. Requires StoreUserActivityTimestamp to be set to True . The default value is set to 600000 milliseconds (10 minutes), and the minimum possible value is 60000 milliseconds (1 minute). If you try to set it to a lower value, you'll get the StoreUserActivityInterval must be at least 60000ms error. |
Output parameters
Type | Description |
---|---|
PubNub Chat | Object returning a new PubNub chat instance. |
Package a Blueprint Project
Because of a bug in Unreal Engine, sometimes C++ plugins fail to load when you package your Blueprint project.
To resolve the Plugin X failed to load
error, you must create a C++ source file in your project otherwise the plugins are going to be excluded.
To resolve the plugin error when building a Blueprint project:
-
In your project, create (Tools-> Add C++ Class) an empty C++ class with
None
as the parent. -
Remove the
Intermediate
,Build
, andBinaries
folders and rebuild the project. -
Reopen the project.
For more information, refer to Unreal Engine Forums.
Next steps
Now that you've initialized and configured the Unreal Chat SDK, you can start creating channels, adding users, and powering your app with all sorts of features.