Friends

Steam Friends is a core component of the Steam platform that enhances the social experience of gaming by connecting players in real time. In this article, we’ll explore the Steam Friends interface provided by the Steamworks SDK, which offers a rich set of features for managing user profiles, friend lists, game invitations, and in-game communication. Whether you’re looking to integrate friends’ status updates or create custom matchmaking experiences, understanding Steam Friends is essential for creating a more connected and engaging game environment.

Examples

Friend Profile

Steam provides a lot of rich information about your friends, and this can be used in-game for many purposes, such as a visually rich display for your local user and or the other players they are playing with.

Code Free

See the Prefabs and our Example scene for a working demonstration of the Friend List component.

A simple control that can read detailed information about a user and help you display that information on the screen in a rich manner.

Each aspect of the profile is optional, if you leave the reference field empty, then it will simply be ignored. For example, here we have left the Level field empty so the player's Steam Level will not be displayed.

C#

//Assumes
UserData user; //= This is the user you want to read data for
//For the local user UserData.Me can be used such as
string name = UserData.Me.Name;

// Examples of getting each of the relevant fields
string name = user.Name;
string nickname = user.Nickname;
user.LoadAvatar(image =>
{
    //image is the Texture2D you can use
});
EPersonaState status = user.State;
int level = user.Level;

Friend List

Tools for querying the list of friends are available and allow you to create detailed visual friend lists using your engine of choice's built-in UI tools.

Code Free

See the Prefabs and our Example scene for a working demonstration of the Friend List component.

Friend Groups Display handles query and display of the local user's friends, loading each found friend into the corresponding "Collection". You can leave a collection null if you do not want to use that particular collection

The Group Prefab field uses a Friend Group component, which controls the header and display of each of the collections.

The Record Template field in the group uses the Friend Profile component to display each friend that is found to fit this group.

C#

//Get an array of the player's friends
UserData[] myFriends = UserData.MyFriends;

//You can now loop through that list and read the profile information
foreach(var friend in myFriends)
{
    //Get the name and whatever else you might like to do with it
    string name = friend .Name;
}

Hex ID

You can get a friend's ID or share your ID as a Hex value. This is generally smaller and more human-friendly than asking a user to type in or share a full Steam ID.

Code Free

Not Applicable

C#

To get the hex ID of a known friend, including yourself

//Given a UserData, such as read from your friends list
UserData myFriend;
// or from yourself
UserData.Me;

//The hex ID can be had directly
string hexID = myFriend.HexId;
//Or via the ToString
string hexID = myFriend.ToString();

If you have a Hex ID and need to get the UserData

UserData myFriend = UserData.Get(hexId);

Invite to Game

You can invite a friend to play a game with you, Note this is inviting them to a connection string, not a lobby. It is possible to invite a friend to a lobby as well, We will explain that in the Lobby article.

Code Free

Not applicable.

C#

Invite the user to the game

//Given a UserData, such as read from your friends list
UserData myFriend;

//With a valid friend, we can simply "Invite To Game", sending them 
//A connection string which can be anything you need it to be
myFriend.InviteToGame("whatever connection string you need");

The user will see the invite in their Friend chat and can accept the invite there. When they accept the invite, what happens next depends on whether or not they are currently playing this game.

If they are playing this game, then the Rich Presence Join Requested event will be raised. You can listen to this event via our Steamworks Event Triggers

Or you can listen in code

using Heathen.SteamworksIntegration.API;

Overlay.Client.EventGameRichPresenceJoinRequested.AddListener(HandleJoinRequest);

private void HandleJoinRequest(UserData whoInvitedYou, string connectionStringTheyPassed)
{
    //Handle the event
}

If the user was not already playing the game when they clicked the Accept button. Then, Steam will launch the game with the connection string on the command line. Valve doesn't document this well, but this code should get you going with reading the command line value.

// Get all command-line arguments
string[] args = Environment.GetCommandLineArgs();
        
// Loop through each argument to find one that starts with "connect="
foreach (string arg in args)
{
    if (arg.StartsWith("connect="))
    {
        // Extract and return the connection string (everything after "connect=")
        return arg.Substring("connect=".Length);
    }
}

Last updated