Skip to main content

Find user by display name or friend code

You can fetch a user account based on a display name (only for Epic Games accounts on the friends list), or by friend code.

Query a user by their display name

To lookup a user by their display name, call QueryUserIdMapping on the user interface, like so:

#include "OnlineSubsystem.h"
#include "OnlineSubsystemUtils.h"
#include "Interfaces/OnlineUserInterface.h"

// ...

IOnlineSubsystem *Subsystem = Online::GetSubsystem(WorldContextObject->GetWorld());
IOnlineIdentityPtr Identity = Subsystem->GetIdentityInterface();
IOnlineUserPtr User = Subsystem->GetUserInterface();

User->QueryUserIdMapping(
*Identity->GetUniquePlayerId(0) /* The local user looking up the accounts */,
DisplayNameInput /* The display name to search */,
IOnlineUser::FOnQueryUserMappingComplete::CreateLambda([](
bool bWasSuccessful,
const FUniqueNetId &UserId,
const FString &DisplayNameOrEmail,
const FUniqueNetId &FoundUserId,
const FString &Error)
{
// If bWasSuccessful, then the user's ID is in FoundUserId.
}));

Query a user by their friend code

To query a user by their friend code (from the friendCode attribute), use the same code as shown above, but instead of passing a display name, pass a value of FriendCode:<friendCode>, replacing <friendCode> with the actual friend code.