Introduction #
Rich Presence is the small set of key-value pairs Steam lets you attach to a user’s current session. Friends List, the overlay, and a user’s profile all read these values to show what someone is doing, things like “In Menu”, “Exploring the Ashlands”, or “In a match, 3-1”. The “Join Game” button is only shown if the “connect” key is set and works with the “Rich Presence Join Requested” event.
- Valve’s Documentation https://partner.steamgames.com/doc/api/ISteamFriends#rich_presence
You can test what your keys actually render as at https://steamcommunity.com/dev/testrichpresence, this is worth bookmarking, it’s the fastest way to check your steam_display formatting without alt-tabbing to a friend’s profile every time.
Understanding the keys #
Rich presence is just key-value pairs, string to string. You get up to 30 keys per user, each key up to 64 characters and each value up to 256 characters. You can set whatever keys you want for your own use, custom UI, matchmaking hints, whatever, but a handful of keys are special because Steam itself reads them:
steam_display— a localisation token that controls what Friends List actually shows for this user. It takes the form#StatusFormatand Steam resolves it against localisation tokens you define in your Steamworks settings, which can in turn reference other rich presence keys as substitutions (#Status_InLevelresolving to something like “In level %level%” where%level%pulls from your ownlevelkey). This is the one Valve’s test page is built around. You can read more in Valve’s documentation.status— a plain-text fallback some older UI paths and third-party tools read directly, not as important assteam_displaybut cheap to set alongside it.connect— the connection string Steam hands to a joining friend, either on the command line if your game isn’t running yet, or via the join-requested event if it already is. This is what makes the “Join Game” button appear at all; without aconnectkey set, Steam has nothing to hand off and won’t show the button.steam_player_group/steam_player_group_size— group friends together under one “Playing together” heading in Friends List instead of listing them individually. Useful once you’ve got more than a couple of friends in the same match.
Everything below covers setting, reading, and clearing these keys. For the actual invite call and handling someone accepting a connect invite, see the User article’s Join Game section, that’s the same underlying event this article’s connect key feeds.
Setting Rich Presence #
Code Free
Drop a Rich Presence Setter component on any object. It applies its With Focus set of keys on enable, and can optionally swap to a separate Without Focus set when the player alt-tabs out, handy for “AFK” style presence without writing any code.
[Screenshot Coming Soon]
For anything more dynamic than a fixed set of keys, use a Presence State asset (Heathen/Steamworks/Presence State in the Create menu) to author a named set of keys you can apply from a Unity Event, and the Rich Presence Inspector window (Window/Heathen/Steamworks/Rich Presence Inspector) to watch what’s actually live on Steam right now while you’re testing, capture it into an asset, or quick-set a single key without touching code at all.
[Screenshot Coming Soon]
C#
// Set one key
SteamTools.Game.User.SetRichPresence("status", "In the Ashlands");
// Set several at once
SteamTools.Game.User.RichPresence = new StringKeyValuePair[]
{
new StringKeyValuePair { key = "steam_display", value = "#Status_InLevel" },
new StringKeyValuePair { key = "level", value = "Ashlands" },
new StringKeyValuePair { key = "connect", value = "+connect 127.0.0.1:27015" },
};
Reading Rich Presence #
Reading your own values back is rarely useful, you set them, you know what they are, the useful case is reading a friend’s. Steam only guarantees a friend’s rich presence data is current if they’re actually a friend and you’ve received a presence-update callback for them, if you need it for someone in your lobby or on your server who isn’t a friend, request it first.
Code Free
Rich Presence Reader is the code-free option, point its User field at a UserData (drag one in, or set it at runtime) and it keeps a live Values dictionary in sync, firing On Update whenever Steam tells us that friend’s presence changed.
[Screenshot Coming Soon]
C#
// Read a specific key for a friend
string status = SteamTools.Game.Friends.GetFriendRichPresence(someFriend, "status");
// Read everything a friend currently has set
Dictionary<string, string> all = SteamTools.Game.Friends.GetFriendRichPresence(someFriend);
// If they're not a friend, or you haven't heard from them in a while, ask Steam to refresh it
SteamTools.Game.Friends.RequestFriendRichPresence(someFriend);
Clearing Rich Presence #
Clear it when the player quits to the main menu, or whenever your current status stops being meaningful, stale presence sitting in a friend’s list looks worse than none at all.
SteamTools.Game.User.ClearRichPresence();
The Join Game button #
Once a friend has a connect key set, Steam shows a Join Game option next to their name in Friends List and lets you send them an invite carrying the same kind of connection string. That full flow, inviting a friend, handling the event on the receiving end whether or not the game was already running, is covered in the User article, this article only owns getting the connect key itself set correctly.