# Enable Presence in the SDK

This how-to walks you through how to enable presence in your game.

### Prerequisites

* [A LootLocker account](https://lootlocker.com/sign-up)
* [An existing game in the Web Console](https://docs.lootlocker.com/)
* [Basic Presence Enabled in the Web Console](/players/presence/how-to/enable-presence-in-web-console.md)

### Enabling Presence

Basic Presence just needs to be enabled in the SDK and the Web Console, after that, playtime data will automatically be sent to LootLocker [to be viewed](/players/presence/how-to/view-presence-in-web-console.md).

{% tabs %}
{% tab title="Unity" %}
Navigate to **Player Settings** -> **LootLocker SDK**. Select **Enable Presence**

![](/files/RPLN4pgaJzg9CdglgNxh)

#### Presence Settings

After Presence is enabled, you can toggle settings to change some of the behaviour.

* **Auto Connect**
  * Should Presence be connected automatically when a LootLocker Session exists?
  * Can be controlled at runtime with `LootLockerSDKManager.SetPresenceAutoConnectEnabled()`
  * Presence can be manually connected by calling `LootLockerSDKManager.ForceStartPresenceConnection(<callback>, <optional player ulid>)`
* **Auto Pause Presence**
  * Disconnect Presence when application loses focus or is paused
  * Useful for battery saving
  * Can be controlled at runtime with `LootLockerSDKManager.SetPresenceAutoDiscconnectOnFocusChangeEnabled()`
  * Presence can be manually disconnected by calling `LootLockerSDKManager.ForceStopPresenceConnection(<callback>, <optional player ulid>)`
* **Enable Presence in Editor**
  * Uncheck this if you do not want development to affect your Presence data.
    {% endtab %}

{% tab title="Unreal" %}
Navigate to **Project Settings** -> **Plugins** -> **LootLocker SDK**. Select **Enable Presence**

![](/files/RhvLSbFQTwUMrVRQRpLG)

#### Presence Settings

After Presence is enabled, you can toggle settings to change some of the behaviour.

* **Auto-connect on Session Start**
  * Should Presence be connected automatically when a LootLocker Session starts?
  * Can be controlled at runtime with `SetPresenceAutoConnectEnabled()`
  * Presence can be manually connected by calling `ForceStartPresenceConnection(<callback>, <optional player ulid>)`
* **Auto-disconnect on Focus Loss**
  * Disconnect Presence when application loses focus or is paused
  * Useful for battery saving
  * Can be controlled at runtime with `SetPresenceAutoDisconnectOnFocusChangeEnabled()`
  * Presence can be manually disconnected by calling `ForceStopPresenceConnection(<callback>, <optional player ulid>)`
* **Enable Presence in Editor**
  * Uncheck this if you do not want development to affect your Presence data.
    {% endtab %}

{% tab title="REST" %}
Presence uses a Websocket connection. First initialize a user session with REST for any aof the [authentication methods](https://ref.lootlocker.com/game/authentication-folder-2066317). When the user is authorized, open up a websocket connection to `ws://domain_key.lootlocker.com/game/presence/v1` with the first message being:

```bash
{"token": "the_signed_in_users_session_token"}
```

You will get back a response saying if you were authenticated or not:

```bash
{"authenticated":true}
```

The web socket will disconnect automatically after 1 minute of no activity. We recommend to send a ping once per minute to cover any network delays or interruptions. If the Websocket is disconnected, you will need to reconnect again.

```bash
{"type":"ping"}
```

Response:

```bash
{"type":"pong"}
```

{% endtab %}
{% endtabs %}

### Interact with the Presence system

For more detailed control, or to read data about the current presence connection there are some interfaces in the SDK you can interact with. The two main use cases are:

* Manual control of when presence connections are made.
* Read information about the presence connection.

#### Manual Presence Control

{% tabs %}
{% tab title="Unity" %}
**Presence Methods**

If auto connect is disabled in the SDK, then when you have authenticated a user with LootLocker you can at any time call `LootLockerSDKManager.ForceStartPresenceConnection(<callback>, <optional player ulid>)`.

To disconnect, call `LootLockerSDKManager.ForceStopPresenceConnection(<callback>, <optional player ulid>)`.

To disconnect all active connections call `LootLockerSDKManager.ForceStopAllPresenceConnections()`.
{% endtab %}

{% tab title="Unreal" %}
**Presence Methods**

If auto connect is disabled in the SDK, then when you have authenticated a user with LootLocker you can at any time call `ForceStartPresenceConnection(<callback>, <optional player ulid>)`.

To disconnect, call `ForceStopPresenceConnection(<callback>, <optional player ulid>)`.

To disconnect all active connections call `ForceStopAllPresenceConnections()`.
{% endtab %}
{% endtabs %}

#### Presence Connection Information

{% tabs %}
{% tab title="Unity" %}
**Presence Methods**

To check if presence is currently connected for a player, call `LootLockerSDKManager.IsPresenceConnected(<optional player ulid>)`. Or for more granular information, call `LootLockerSDKManager.GetPresenceConnectionState(<optional player ulid>)`.

To see detailed information about the current connection for a player, call `LootLockerSDKManager.GetPresenceConnectionStats(<optional player ulid>)`. This will give you a struct with lots of interesting information, such as the current latency towards LootLocker and how long the connection has been running.
{% endtab %}

{% tab title="Unreal" %}
**Presence Methods**

To check if presence is currently connected for a player, call `IsPresenceConnected(<optional player ulid>)`. Or for more granular information, call `GetPresenceConnectionState(<optional player ulid>)`.

To see detailed information about the current connection for a player, call `GetPresenceConnectionStats(<optional player ulid>)`. This will give you a struct with lots of interesting information, such as the current latency towards LootLocker and how long the connection has been running.
{% endtab %}
{% endtabs %}

### Conclusion

In this how-to we have enabled Basic Presence in the SDK. To learn how to interpret this information, continue to the [View Presence in Web Console](/players/presence/how-to/view-presence-in-web-console.md) or continue to read up on [Rich Presence](/players/presence/how-to/using-rich-presence-in-game.md) and it's use cases.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.lootlocker.com/players/presence/how-to/enabling-presence-in-game.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
