Integrate Pubnub with your Unreal Project
A simple way to integrate your Pubnub app with your in-game chat
Introduction
To connect Pubnub to your in-game experience, you can make use of Pubnub's Publish, Subscribe, and History functionality to send, receive and list all messages sent to specific channels.
This can be done in both:
Your Unreal Project by making use of Pubnub's APIs.
Your web application using Pubnub's documented SDKs
This guide covers setting up Pubnub to work within your Unreal project.
For information on setting up Pubnub in a web project, we recommend checking out Pubnub's own documentation on their chat SDKs and core SDKs, as well as how to publish and subscribe to messages via their APIs.
Setting up Pubnub in your Editor
Retrieving your Keys
When creating your Pubnub application and keyset, you will find that each keyset has a Publish, Subscribe, and Secret Key associated with it. For the purposes of implementing Pubnub chat in your project, you will need to note down your Publish and Subscribe key, as these will be used as part of the API requests.

In addition to needing these keys, every request made must be associated with a Pubnub Channel. There is no special set-up required to create a new channel - they are created automatically when providing a value for channel name in any of the API calls.
Pubnub APIs
We will be making use of 3 key APIs as part of integrating pubnub with the in-game chat component:
Publish API (POST):
https://ps.pndsn.com/publish/{
my-pub-key
}/{
my-sub-key
}/0/{
my-channel-name
}
/0?uuid={my-unique-id}&auth={my-auth-token}
Subscribe API (GET):
https://ps.pndsn.com/v2/subscribe/{
my-sub-key
}/{
my-channel-name
}
/0?uuid={my-unique-id}&tt={my-time-token}&tr={my-region}&auth={my-auth-token}
History API (GET):
https://ps.pndsn.com/v3/history/sub-key/{
my-sub-key
}/channel/{
my-channel-name
}
?include_message_type=true&include_uuid=true&include_meta=true&max=100&uuid={my-unique-id}&auth={my-auth-token}
Important Blueprints
There are 2 blueprints that will aid you in implementing Pubnub supported chat:
BP_M2_PubnubConnection
: this is a helper blueprint that handles the construction of the pubnub API urls, and handles the sending of all requests. We recommend looking through this blueprint, as well as the TextChatcomponent, to get an understanding of how both blueprints work together to retrieve data from Pubnub and display it in the text chat widget.BPMC_Pubnub_TextChatComponent
: this is an example text chat component hooked up to pubnub (usingBP_M2_PubnubConnection
), which handles sending messages and listening to messages. It is just missing authentication, which will need to be provided to make this work.
Modifying the BP_Pubnub_TextChatComponent Blueprint
In the example content, the chat widget (WBP_M2Example_TextChat
)is controlled by the blueprint BPMC_M2Example_TextChatComponent
. You will need to:
Make a copy of
BPMC_Pubnub_TextChatComponent
andWBP_M2Example_TextChat
.In your copy of
BPMC_Pubnub_TextChatComponent
, fill in the following fields:SubscribeKey
PublishKey
ChannelName
AuthToken
(optional)The channel name as mentioned above can be defined as anything you like. When initializing the Channel Name variable, ensure you give it a default value so that in cases where world/launch context id does not exist, your chat will still be sent to your default channel. You can use any unique identifier for channel name; for example, you can use our helper node
Get M2 Web Platform World ID
to retrieve the world's unique id. This will ensure that each launched world will use a separate Pubnub chat channel, so messages are properly gated.
In your copy of
WBP_M2Example_TextChat
, update the logic inOnBootflowFinished
to get and listen to the events on your custom text chat component instead ofBPMC_M2Example_TextChatComponent
Add your custom text chat component to your BPM (e.g.
BPM_Example_PlayerCharacter
)Replace the
WBP_M2Example_TextChat
with your updated widget in your HUD (e.g.WBP_Example_HUD
)
If everything is set up correctly, you should be able to send messages using the chat widget in PIE as before, and the history of the chat should be shown in the in-game chat!

Last updated
Was this helpful?