User Data
Useing Steam User Data

Introduction

The UserData object provides quick and efficent access to the details and artifacts pertaining to any given user. Heathen's UserData object is interchaingable with CSteamID and ulong and can be created by simply casting or assigning from those values.
1
UserData user_fromUlong = 1234566;
2
UserData user_fromCSteamID = new CSteamID(1234566);
3
UserData user = UserData.Get(1234566);
Copied!
The UserData object is a structure and as such is a value type, it only stores the CSteamID of the user it relates to and reads all other information at the time of request from Steam's local cashe. As this object reads from Steam cashe it is possible to try to read data for a user that is not cashed resulting in empty or partial information.
In general you can only access user information for a user that the local user "knows". This is defined by Steam as users that:
  • Are friends
  • Share a clan or group (some limitations apply regarding large groups)
  • Share a lobby
  • Share a game server
You may be able to get limited information for additional users such as user's found on a leaderboard that you have quried.
If you need to request information for a user your local user does not "know" you should call API.Friends.Client.RequestUserInformation(user, getNameOnly). You should avoid doing this if possible, in most cases there is no reason to get a user's information for a user that the local user does not "know".

Definition

1
public struct UserData;
Copied!

Fields and Attributes

Me

1
public static UserData Me => get;
Copied!
This simply returns the local user's UserData and is the same as calling API.User.Client.Id

cSteamId

1
public CSteamID cSteamId;
Copied!
This is simply the native CSteamID value as used by Steam's APIs you do not need to read or set this directly as the UserData object is implicitly assignable and convertable to CSteamID and ulong.

IsMe

1
public bool IsMe => get;
Copied!
This is true if this UserData object is the local user

SteamId

1
public ulong SteamId { get; set; }
Copied!
This gets or sets the ID by its ulong value

Avatar

You can use the SetUserAvatar component to more easily manage a given user's avatar texture. The SetUserAvatar componenet will assign a RawImage with the texture and will monitor Steam API for changes to that avatar thus if that user changes there avatar image it will automatically update the RawImage texture.
1
public Texture2D Avatar => get;
Copied!
This is the texture loaded for this user's avatar if it has been loaded. Note you must call LoadAvatar for this user before this value will be set i.e.
1
if(user.Avatar == null)
2
user.LoadAvatar((result) =>
3
{
4
rawImage.texture = result;
5
});
6
else
7
rawImage.texture = user.Avatar;
Copied!

Name

You can use the SetUserName component to more easily manage a given user's name. The SetUserName componenet will assign a uGUI Text or TMPro Text with the name or nickname of the indicated user and will update it if that name should change.
1
public string Name => get;
Copied!
This reads the user's Steam Name

Nickname

You can use the SetUserName component to more easily manage a given user's name. The SetUserName componenet will assign a uGUI Text or TMPro Text with the name or nickname of the indicated user and will update it if that name should change.
1
public string Nickname => get;
Copied!
This reads the nickname set for this user by the local user if any. If none then this will be the same as Name.

State

1
public EPersonaState State => get;
Copied!
Returns the EPersonaState value for this user.

InGame

1
public bool InGame => get;
Copied!
Is this user in a game?

GameInfo

1
public FriendGameInfo_t GameInfo => get;
Copied!
Returns the FriendGameInfo_t discribing the game ID, connection information and lobby ID if any that this user is related to.

Level

1
public int Level => get;
Copied!
Gets the Steam user level for this user.

AccountId

1
public AccountID_t AccountId => get;
Copied!
Returns the AccountID_t also called a "Friend ID" this is mostly used internally by Steam API but is used in a few API calls such as UGC Query.

FriendId

1
public uint FriendId => get;
Copied!
Returns the uint value of the AccountId.

Methods

ClearRichPresence

1
public static void ClearRichPresence()
Copied!
Clears the rich presence data for the local user.

Get

1
public static UserData Get( .. );
Copied!
This method is a static method that can be used to fetch the user data for any given user or for the local user. You can pass in a CSteamID or its ulong equivlent to fetch the user data for other users. If you do not pass in an id this method will return the local user's user data.

GetGamePlayed

1
public bool GetGamePlayed(out FriendGameInfo_t gameInfo);
Copied!
Functionally the same as calling API.Friends.Client.GetFriendGamePlayed(user.cSteamId, out results). This returns rather or not the user is in a game and if so the results will be populated with information about that game.

InviteToGame

1
public void InviteToGame(string connectString)
Copied!
Invites the target user to a game passing in the connection string. This will cause the GameRichPrecenseJoinRequest event to be raised on the invited user if present in game, or will launch the game with the connectionString in the command line if not.

InviteToLobby

1
public bool InviteToLobby(Lobby lobby)
Copied!
Invites the target user to join a specific lobby. This will cause the GameLobbyJoinRequest event to be raised on the invited user when accepted if present in game or will launch the game with the lobby ID in the command line if not in game.

LoadAvatar

1
public void LoadAvatar(Action<Texture2D> callback);
Copied!
Functionally the same as calling API.Friends.Client.GetFriendAvatar(user.cSteamId) . This starts the process of loading the avatar image from Steam cashe if its not already loaded into memory.
The callback on this method will include the loaded texture, the loaded texture can also be found via user.Avatar.
1
//Assuming a RawImage named rawImage;
2
user.LoadAvatar((result) =>
3
{
4
rawImage.texture = result;
5
});
Copied!

SendMessage

1
public bool SendMessage(string message);
Copied!
Sends the user a message via the Replay To Friend feature.
If this returns false then the current user is rate or chat limited by Valve.

SetRichPresence

1
public static bool SetRichPresence(string key, string value)
Copied!
Sets a rich presence value on the local user.