Initial configuration

Before building your chat app, you must initialize and configure the Unity 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 Unity 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.

Keyset configuration

Each keyset has its own configuration settings in the Admin Portal. To develop some features in your chat app, you must enable appropriate settings on your app's keyset on the Admin Portal.

For example, to create or update users in your chat, you'll need to enable App Context on the keyset for PubNub to manage that user metadata. Similarly, you'll need to enable Presence to track a user's channel presence or enable Message Persistence to store messages in PubNub history. You can enable these features at any time - the docs will instruct you and show which setting needs enabling on your keyset for a given chat feature to work.

Download the SDK

Download the SDK from any of the following sources:

Get the source code

https://github.com/pubnub/unity-chat.git?path=/unity-chat/PubnubChatUnity/Assets/PubnubChat

Install via Package Manager

  1. Open Unity Editor and navigate to Window -> Package Manager.

  2. In the Package Manager window, click + and select Add package from git URL.

  3. Paste the PubNub Unity package link and click Add.

    https://github.com/pubnub/unity-chat.git?path=/unity-chat/PubnubChatUnity/Assets/PubnubChat

    Add Unity package

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 Unity Chat SDK, create a new Chat object.

var chat = new Chat(new PubnubChatConfig(
"PublishKey",
"SubscribeKey",
"UserId",
"AuthKey",
"typingTimeout")
);

Input parameters

ParameterTypeRequiredDefaultFeatureDescription
PublishKeystringYesn/aSend messagesSpecifies the key used to publish messages on a channel.
SubscribeKeystringYesn/aReceive messagesSpecifies the key used to subscribe to a channel.
UserIdstringYesn/an/aUnique 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.
AuthKeystringNon/aAccess ManagerAuthentication key for Access Manager. Use it for all requests made to PubNub APIs to authenticate users in your application and grant them access to PubNub resources (other users' metadata and channels).
typingTimeoutintNo5000Typing IndicatorSpecifies 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).
typingTimeoutDifferenceintNo1000Typing IndicatorSpecifies the difference in time between actually sending the typing indicator and the value of typingTimeout. This is designed to cover for any network lag that may occur. If you set the typingTimeout to 5 seconds and the typingTimeoutDifference to 1 second, the typing signal stops between the fourth and fifth second. The default value is set to 1000 milliseconds (1 second).

Output parameters

TypeDescription
ChatObject returning a new PubNub chat instance.

Next steps

Now that you've initialized and configured the Unity Chat SDK, you can start creating channels, adding users, and powering your app with all sorts of features.

Last updated on