Unreal Chat SDK Tutorial: Environment Setup

This tutorial will walk you through the features of the Chat SDK, explain the architecture behind building a chat app, as well explore an existing example with our Unreal Engine Chat Showcase Game.

1

To begin, you'll need to install any PubNub dependencies and configure the PubNub Unreal Chat SDK to connect your application to the PubNub network. While you can use either the core Unreal SDK instead of the Unreal Chat SDK to implement text chat, we will be utilizing the Unreal Chat SDK, as it’s more tailored to chat. Learn more about the difference between the Unreal Chat SDK and the Unreal SDK by reading this blog. The best part about either of these SDKs? You can either use the visual scripting language Blueprints or C++ to perform this functionality!

For the sake of simplicity, we will be focusing on the Blueprints approach of this SDK. While the code snippets will be images, our documentation has interactive blueprints that you can directly copy the nodes from and paste into your project. Each feature discussed will have links to our documentation to implement either Blueprints or C++.

  1. Download Unreal Engine 5.0 or higher. The Unreal Chat Showcase game was built using the latest version, which at the time of this article is 5.4.4.
  2. Install Visual Studios, XCode, or Rider as your IDE, depending on your system and preferences.
  3. Clone the repository of the Unreal Engine Chat Showcase game and follow the installation instructions in the readme to install the Unreal Chat SDK. This also includes obtaining your free API keys (which you'll get in the next step) via your PubNub account, which is necessary to connect to the PubNub infrastructure. You’re also welcome to create your own Unreal Engine project or utilize an existing application.
  4. Once you’ve downloaded the game, add the SDKs to the correct Plugins folders and open the game project in the Unreal Editor.
  5. Navigate to All/Content/UI/B_LyraFrontendStateComponent.
  6. Give yourself a User ID that is required by all PubNub SDKs to connect to the platform.
  7. Double-click to open the function InitializePubNub, which lives in the GameInstance.
  8. Add the PubNub keys that you'll obtain in the next step to the InitChat Blueprint.

Before you can start publishing to send messages to other devices and subscribing to receive messages from publishers, as well as incorporate other useful message features, you need to understand the basics of the Unreal Chat SDK, so you can utilize this information when setting up your application.

Understanding the Chat SDK: Chat Entities

The Unreal Chat SDK is part of our Chat SDKs, which offer specialized abstractions for chat use cases and provide more intuitive, chat-focused APIs you can add to new or existing applications.

Every Chat SDK consists of what we call Chat entities, which are the building blocks that make up the SDK so you can easily build, manage, and access all levels of your chat app. Every entity has different methods and properties that allow you to build your chat system. We’ll briefly go over the basics of each of the chat entities, but it’s highly recommended that you go through our extensive documentation to understand each entity and the methods available to each entity.

Chat Entity

The chat entity is the core component you interact with once the Unreal Chat SDK is initialized. It provides access to various methods like creating channels, managing users, and performing operations such as deleting a channel or checking user subscriptions. Initialization requires a Publish Key, Subscribe Key, and User ID, with optional additional settings, as we did in the earlier steps.

You can only have one instance of the chat entity active at a time, so it’s recommended you store it in your GameInstance to access between various levels.

Channel Entity

The channel entity allows you to manage chat channels in your Unreal Engine game. You can create, update, delete, and fetch information about specific channels. Channels are central to organizing chat spaces and can be used to group users together for conversations. You can also retrieve metadata and manage user memberships within each channel.

User Entity

The user entity represents individual users in the chat system. It allows you to create, update, delete, and retrieve information about users, as well as manage the online status of users known as Presence. You can also manage user metadata and track which channels they are a part of. This entity helps you manage user-specific data and actions, ensuring smooth interactions within the chat environment.

Message Entity

The message entity handles sending, retrieving, updating, and deleting messages within your chat application. It allows you to manage the flow of communication between users, ensuring messages are properly delivered and stored. With this entity, you can also track message metadata and manage various message-related actions, such as threading or reactions.

Membership Entity

The membership entity manages the relationship between users and channels in your chat system. It allows you to add or remove users from specific channels, retrieve membership details, and update membership-related metadata. This entity helps maintain user participation within channels and ensures users are subscribed to the right chat spaces.

Event Entity

The event entity allows you to handle real-time events within the chat system, such as user presence, message actions, and channel updates. You can listen to these events to trigger specific actions or updates in your app. Additionally, you can create custom events to extend chat functionality, allowing you to define and respond to unique actions beyond the default chat events, providing greater flexibility and control over your chat environment.

There are a few other entities, but these are the most common and ones you should focus on understanding. Once you’ve read through the documentation on these entities, you are now ready to start building the chat.

BackStep 1 of 4Next