---
source_url: https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/users/presence
title: Presence
updated_at: 2026-06-04T11:09:49.724Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Presence

Track which users are online and active in your chat app. Display user status (online, offline, active, away) and show when users were last active.

The Chat SDK provides two types of presence tracking:

| Type | Description | Data source |
| --- | --- | --- |
| [Channel presence](#channel-presence) | Real-time tracking of users subscribed to specific channels | [Presence API](https://www.pubnub.com/docs/sdks/unity/api-reference/presence) |
| [Global presence](#global-presence) | App-wide activity tracking based on timestamps | [LastActiveTimeStamp](https://www.pubnub.com/docs/chat/unity-chat-sdk/learn/chat-entities/user) property |

**Channel presence** provides real-time updates through the Presence API. Use [StreamPresence()](#get-presence-updates) to track who connects or disconnects.

**Global presence** uses the `LastActiveTimeStamp` property on `User` objects. Configure the update interval (default: 1 minute) during [initialization](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/configuration#input-parameters) with `StoreUserActivityTimestamp`.

## Channel presence

These methods let you monitor who is subscribed to a given channel ("present" on that channel).

:::note Requires Presence
All channel presence methods in this section require that [Presence is enabled](https://youtu.be/i2yLIqmvFD0) for your app's keyset in the [Admin Portal](https://admin.pubnub.com/).
:::

You can retrieve similar information for presence with different methods by calling them on the `User`, `Channel`, or `Chat` object. Depending on the chosen method, you must provide a different input information set.

### Return channels where user is present

You can return a list of channels where a given user is present with:

* `WherePresent()` called on the `User` object
* `WherePresent()` called on the `Chat` object.

Both of these methods have the same name and give the same output. The only difference is that you call a given method either on the `Chat` or the `User` object. Depending on the object, you either have to specify the ID of the user whose presence you want to check or not because it's already known.

#### Method signature

These methods take the following parameters:

* WherePresent() (on the User object) 1user.WherePresent()
* WherePresent() (on the Chat object) 1chat.WherePresent(2 string userId3)

##### Input

| Parameter | Required in the `User` object method | Required in the `Chat` object method | Description |
| --- | --- | --- | --- |
| `userId`Type: `string`Default: n/a | No | Yes | [Unique identifier](https://www.pubnub.com/docs/general/setup/users-and-devices#user-id-usage) (up to 92 UTF-8 characters) of the user whose presence you want to check. |

##### Output

This method returns an awaitable `Task<ChatOperationResult<List<string>>>` with all channel IDs on which the given user is present.

#### Sample code

Get a list of channels on which the `support_agent_15` user is present.

* WherePresent() (on the User object) using System.Collections.Generic; using System.Threading.Tasks; using PubnubApi; using PubnubChatApi; using UnityEngine; // Configuration PubnubChatConfig chatConfig = new PubnubChatConfig(); PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId")) { SubscribeKey = "demo", PublishKey = "demo", Secure = true }; // Initialize Unity Chat var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration); if (!chatResult.Error) { chat = chatResult.Result; } var userResult = await chat.GetUser("support_agent_15"); if (userResult.Error) { Debug.Log("Couldn't find user!"); return; } var user = userResult.Result; var channelIdsResult = await user.WherePresent(); if (!channelIdsResult.Error) { var channelIds = channelIdsResult.Result; }
* WherePresent() (on the Chat object) using System.Collections.Generic; using System.Threading.Tasks; using PubnubApi; using PubnubChatApi; using UnityEngine; // Configuration PubnubChatConfig chatConfig = new PubnubChatConfig(); PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId")) { SubscribeKey = "demo", PublishKey = "demo", Secure = true }; // Initialize Unity Chat var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration); if (!chatResult.Error) { chat = chatResult.Result; } // reference the "chat" object and invoke the "wherePresent()" method. var channelIdsResult = await chat.WherePresent("support_agent_15"); if (!channelIdsResult.Error) { var channelIds = channelIdsResult.Result; }

### Check user's channel presence

You can return information if the user is present on a specified channel with:

* `IsPresentOn()` called on the `User` object
* `IsUserPresent()` called on the `Channel` object.
* `IsPresent()` called on the `Chat` object.

All of these methods give the same output. The only difference is that you call a given method on the `User`, `Channel`, or `Chat` object. Depending on the object, you have to specify the ID of the user whose presence you want to check, the channel ID where you want to check user's presence, or both user and channel IDs.

#### Method signature

These methods take the following parameters:

* IsPresentOn() (on the User object) 1user.IsPresentOn(2 string channelId3)
* IsUserPresent() (on the Channel object) 1channel.IsUserPresent(2 string userId3)
* IsPresent() (on the Chat object) 1chat.IsPresent(2 string userId, 3 string channelId4)

##### Input

| Parameter | Required in the `User` object method | Required in the `Channel` object method | Required in the `Chat` object method | Description |
| --- | --- | --- | --- | --- |
| `userId`Type: `string`Default: n/a | No | Yes | Yes | [Unique ID](https://www.pubnub.com/docs/general/setup/users-and-devices) (up to 92 UTF-8 characters) of the user whose presence you want to check. |
| `channelId`Type: `string`Default: n/a | Yes | No | Yes | Unique identifier of the channel where you want to check the user's presence. |

##### Output

Returns an awaitable `Task<ChatOperationResult<bool>>` information on whether a given user is present on a specified channel (`true`) or not (`false`).

#### Sample code

Find out if the `support_agent_15` user is present on the `support` channel.

* IsPresentOn() (on the User object) using System.Collections.Generic; using System.Threading.Tasks; using PubnubApi; using PubnubChatApi; using UnityEngine; // Configuration PubnubChatConfig chatConfig = new PubnubChatConfig(); PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId")) { SubscribeKey = "demo", PublishKey = "demo", Secure = true }; // Initialize Unity Chat var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration); if (!chatResult.Error) { chat = chatResult.Result; } var userResult = await chat.GetUser("support_agent_15"); if (userResult.Error) { Debug.Log("Couldn't find user!"); return; } var user = userResult.Result; var isPresentOnResult = await user.IsPresentOn("support"); if (!isPresentOnResult.Error) { var isPresentOn = isPresentOnResult.Result; }
* IsUserPresent() (on the Channel object) using System.Collections.Generic; using System.Threading.Tasks; using PubnubApi; using PubnubChatApi; using UnityEngine; // Configuration PubnubChatConfig chatConfig = new PubnubChatConfig(); PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId")) { SubscribeKey = "demo", PublishKey = "demo", Secure = true }; // Initialize Unity Chat var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration); if (!chatResult.Error) { chat = chatResult.Result; } var channelResult = await chat.GetChannel("support"); if (channelResult.Error) { Debug.Log("Couldn't find channel!"); return; } var channel = channelResult.Result; var isPresentResult = await channel.IsUserPresent("support_agent_15"); if (!isPresentResult.Error) { var isPresent = isPresentResult.Result; }
* IsPresent() (on the Chat object) using System.Collections.Generic; using System.Threading.Tasks; using PubnubApi; using PubnubChatApi; using UnityEngine; // Configuration PubnubChatConfig chatConfig = new PubnubChatConfig(); PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId")) { SubscribeKey = "demo", PublishKey = "demo", Secure = true }; // Initialize Unity Chat var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration); if (!chatResult.Error) { chat = chatResult.Result; } var isPresentResult = await chat.IsPresent("support_agent_15", "support"); if (!isPresentResult.Error) { var isPresent = isPresentResult.Result; }

### Return all users present on channel

You can return a list of users present on the given channel with:

* `WhoIsPresent()` called on the `Channel` object
* `WhoIsPresent()` called on the `Chat` object.

Both of these methods have the same name and give the same output. The only difference is that you call a given method either on the `Chat` or the `Channel` object. Depending on the object, you either have to specify the ID of the channel where you want to check all present users or not because it's already known.

#### Method signature

These methods take the following parameters:

* WhoIsPresent() (on the Channel object) 1channel.WhoIsPresent(2 int limit = 1000,3 int offset = 04)
* WhoIsPresent() (on the Chat object) 1chat.WhoIsPresent(2 string channelId3)

##### Input

| Parameter | Required in the `Channel` object method | Required in the `Chat` object method | Description |
| --- | --- | --- | --- |
| `channelId`Type: `string`Default: n/a | No | Yes | Unique identifier of the channel where you want to check all present users. |
| `limit`Type: `int`Default: `1000` | No | No | Maximum number of user details to return. The default and maximum value is `1000`. |
| `offset`Type: `int`Default: `0` | No | No | Starting position of results for pagination purposes. Use this parameter to page through results when there are more users than the `limit` allows. |

##### Output

This method returns an awaitable `Task<ChatOperationResult<List<string>>>` with all user IDs on the channel.

#### Sample code

Get a list of users that are present on the `support` channel.

* WhoIsPresent() (on the Channel object) using System.Collections.Generic; using System.Threading.Tasks; using PubnubApi; using PubnubChatApi; using UnityEngine; // Configuration PubnubChatConfig chatConfig = new PubnubChatConfig(); PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId")) { SubscribeKey = "demo", PublishKey = "demo", Secure = true }; // Initialize Unity Chat var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration); if (!chatResult.Error) { chat = chatResult.Result; } var channelResult = await chat.GetChannel("support"); if (channelResult.Error) { Debug.Log("Couldn't find channel!"); return; } var channel = channelResult.Result; var userIdsResult = await channel.WhoIsPresent(); if (!userIdsResult.Error) { var userIds = userIdsResult.Result; }
* WhoIsPresent() (on the Chat object) using System.Collections.Generic; using System.Threading.Tasks; using PubnubApi; using PubnubChatApi; using UnityEngine; // Configuration PubnubChatConfig chatConfig = new PubnubChatConfig(); PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId")) { SubscribeKey = "demo", PublishKey = "demo", Secure = true }; // Initialize Unity Chat var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration); if (!chatResult.Error) { chat = chatResult.Result; } var userIdsResult = await chat.WhoIsPresent("support"); if (!userIdsResult.Error) { var userIds = userIdsResult.Result; }

### Get presence updates

Get up-to-date information about the real-time presence of users in the specified channel by [subscribing to Presence events](https://www.pubnub.com/docs/general/presence/presence-events#subscribe-to-presence-channel).

Use the `StreamPresence()` method to enable or disable presence event streaming on a channel, and the `OnPresenceUpdate` event to handle presence updates. This lets you constantly track who connects to or disconnects from the channel and visually represent that in your chat app through some status, like `Offline`, `Online`, `Active`, `Away`, or any other.

:::tip Method naming
Earlier versions used `SetListeningForPresence()` to enable streaming. This method has been superseded by `StreamPresence()`, though it remains available for backward compatibility.
:::

#### Method signature

These methods take the following parameters:

* StreamPresence() 1channel.StreamPresence(bool stream)
* OnPresenceUpdate - Event signature 1// event on the Channel entity2public event Action<List<string>> OnPresenceUpdate;3// needs a corresponding event handler4void EventHandler(List<string> users)

#### Input

| Parameter | Required in `StreamPresence()` | Required in `OnPresenceUpdate` | Description |
| --- | --- | --- | --- |
| `stream`Type: `bool`Default: n/a | Yes | n/a | Whether to start (`true`) or stop (`false`) listening to presence events on the channel. |
| `users`Type: `List<string>`Default: n/a | No | Yes | List of user IDs present on the channel. |

#### Output

These methods don't return a value. Presence updates are delivered through the `OnPresenceUpdate` event handler.

#### Sample code

Get user presence updates on `support` channel.

```csharp
using System.Collections.Generic;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
var channelResult = await chat.GetChannel("support");
if (channelResult.Error)
{
    Debug.Log("Couldn't find channel!");
    return;
}
var channel = channelResult.Result;

channel.OnPresenceUpdate += OnPresenceUpdateHandler; // or use lambda

void OnPresenceUpdateHandler(List<string> users)
{
    Debug.Log($"Users present: {string.Join(", ", users)}");
}
```

## Global presence

The Unity Chat SDK lets you configure your app to track the user's last online activity - this gives near real-time visibility into the availability of other chat members, allowing you to see whether someone is offline or available and reach out to them to start immediate communication.

Using this online activity information provided by the Chat SDK, you can later configure your app to display different statuses next to user profiles, like `Offline`, `Online`, `Active`, `Away` or any other.

This feature relies on the [LastActiveTimeStamp](https://www.pubnub.com/docs/chat/unity-chat-sdk/learn/chat-entities/user) property set in milliseconds on the `User` object. This property stands for the Unix timestamp (numeric value representing the number of seconds since January 1, 1970) for the last time the user was active in a chat app. To track this, you must explicitly state that when configuring your app during the [Unity Chat SDK initialization](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/configuration#initialize-pubnub) by:

* Setting the `StoreUserActivityTimestamp` parameter to `true`.
* Deciding how frequently a user's online activity will be updated by configuring the `StoreUserActivityInterval` option - the default value is set to `60000` milliseconds (1 minute).

If you set these options, you can track a user's global presence by accessing the `Active` property on the User object that relies on the above setup. If the user showed no online activity within the defined period of time, they are considered inactive.

### Check user's app presence

You can access the `Active` property of the [User object](https://www.pubnub.com/docs/chat/unity-chat-sdk/learn/chat-entities/user) to check whether a user has recently been active in the chat app based on their last activity timestamp and a configured interval.

:::note Required configuration
To track the user's online activity, you must first configure the `StoreUserActivityTimestamp` and `StoreUserActivityInterval` parameters when [initializing the Unity Chat SDK](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/configuration#initialize-pubnub).
:::

#### Method signature

This is how you can access the property:

```csharp
user.Active: bool
```

##### Properties

| Property | Description |
| --- | --- |
| `Active`Type: `bool` | Returned info on whether the user is active (`true`) or not active (`false`) on the channel. The returned value depends strictly on how you configure your chat app during [initialization](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/configuration#initialize-pubnub) - if you set the `storeUserActivityInterval` parameter to the default `60000` milliseconds (1 minute) and the user has been active in the app within the last 1 minute (based on their `LastActiveTimeStamp` property), accessing the `Active` property returns `true`. |

#### Sample code

Check if the user `support_agent_15` has been recently active (assuming you configured the chat app to use the default activity interval value).

```csharp
using System.Collections.Generic;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
var userResult = await chat.GetUser("support_agent_15");
if (!userResult.Error)
{
    var user = userResult.Result;
    Debug.Log($"Is user active?: {user.Active}");
}
else 
{
    Debug.Log("User not found.");
}
```

### Check user's last online activity

:::note Required configuration
To track the user's online activity, you must first configure the `StoreUserActivityTimestamp` and `StoreUserActivityInterval` parameters when [initializing the Chat SDK](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/configuration#initialize-pubnub).
:::

Let's assume you configured your app to track the user's online activity and update it every 2 minutes. You can retrieve information on the user's last online activity directly from the `User` object (`LastActiveTimeStamp` property), convert it to a human-readable date (using external date and time libraries), and display it next to the user's profile in your chat app. Thanks to that, other app users will be able to see the last time the given user was online.

#### Method signature

This is how you can access the property:

```csharp
user.LastActiveTimeStamp: string
```

##### Properties

| Property | Description |
| --- | --- |
| `LastActiveTimeStamp`Type: `string` | Timestamp for the last time the user was active in a chat app. |

#### Sample code

Show the Unix timestamp when `support_agent_15` was last time active in an app.

```csharp
using System.Collections.Generic;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
// Get the user's last active timestamp
var userResult = await chat.GetUser("support_agent_15");
if (!userResult.Error)
{
    var user = userResult.Result;
    Debug.Log($"User last active timestamp: {user.LastActiveTimeStamp}");
}
else 
{
    Debug.Log("User not found.");
}
```