# Using Rich Presence in Game

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

### Prerequisites

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

### Rich Presence

Rich Presence does not require any changes for setup in the SDK.

### Sending Status Changes

When sending state changes for a player, you need to provide:

* **A status name**
  * E.g. "main\_menu", "level\_1", "settings\_menu"
* **Metadata** (Optional)
  * You can include metadata when sending the state update
    * E.g. "build\_version", "game\_fps\_count"

{% tabs %}
{% tab title="Unity" %}
Sending a Presence status is as simple as calling a function.

```csharp
// Example code of a function being called when the player enters a Game Over state
public void SendGameOverPresenceStatus()
{
    Dictionary<string, string> presenceDetails = new Dictionary<string, string>()
    {
        {"device", SystemInfo.deviceModel },
        {"unity_version", Application.unityVersion}
    };
    LootLockerPresenceManager.UpdatePresenceStatus("game_over", presenceDetails);
}
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="/files/LPGl8mi9VM9BB2Ch7RPm" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/-0b1h50b/">Blueprint example of updating presence status</a></p></figcaption></figure>
{% endtab %}

{% tab title="REST" %}
Presence uses a Websocket connection. First initialize a user session with REST for any of 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:

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

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

```
{"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.

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

Response:

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

To send Rich Presence Statuses, send a message with the following structure:

```
{
    "metadata": {
        "key1": "value1",
        "key2":"value2"
    },
    "status": "game_status_to_send"
}
```

{% endtab %}
{% endtabs %}

### Out of Focus / Pause behaviour

When **Auto Connect** and **Disconnect On Pause** is enabled Presence will reconnect and resend the last status that was sent when Presence reconnects.

### Conclusion

In this how-to we have used Rich Presence to send a change of game status. 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).


---

# 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/using-rich-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.
