On this page

Chat object

The Chat object is your entry point to the Chat SDK after initialization. Use the Chat object to create and manage channels, users, messages, memberships, and other entities.

Key capabilities:

  • Create and delete channels and users
  • Track user presence across channels
  • Send custom events
  • Access the underlying Unity SDK

Properties

The Chat object has the following properties:

1// Unity-specific factory — lives on the UnityChat static class
2public static async Task<ChatOperationResult<Chat>> UnityChat.CreateInstance(
3 PubnubChatConfig chatConfig,
4 PNConfiguration pubnubConfig,
5 bool webGLBuildMode = false,
6 bool unityLogging = false)
7
8// Pass an existing Pubnub instance
9public static async Task<ChatOperationResult<Chat>> UnityChat.CreateInstance(
10 PubnubChatConfig chatConfig,
11 Pubnub pubnub)
12
13// Pass a PNConfigAsset Scriptable Object
14public static async Task<ChatOperationResult<Chat>> UnityChat.CreateInstance(
15 PubnubChatConfig chatConfig,
show all 30 lines

To initialize the Chat SDK, you must provide a PNConfiguration object with PublishKey, SubscribeKey, and UserId. Read the Configuration page for all parameters and defaults.

Events

The Chat object has the following events:

1// Base event that is generated each time any other event type is generated
2public event Action<ChatEvent> OnAnyEvent;

Example

Get an event that is triggered when any chat event occurs.

1

Methods

You can call the following methods on the Chat object.

Click on each method for more details.

Standard methods

Streaming methods

These methods register or unregister real-time event subscriptions. Each streaming method activates one or more of the events listed in the Events section above.

Use case

For example, you can use the Chat object methods to:

Last updated on