One thing to note is that the GetAppName
function from Steam’s ISteamAppList Interface requires that the App List has been retrieved first using the RequestAppList
function. This ensures that the list of apps is up to date before attempting to retrieve any app names.
Here’s an updated version of your function that includes a call to RequestAppList
before calling GetAppName
:
void USteamFriendsFunctionLibrary::GetSteamFriendGame(const FSteamFriend SteamFriend, ESteamFriendAsyncResultSwitch& Result, FString& GameName)
{
if (!SteamFriend.UniqueNetID.IsValid())
{
Result = ESteamFriendAsyncResultSwitch::OnFailure;
return;
}
if (SteamAPI_Init())
{
// Convert the ID to a uint64 pointer
uint64 ID = ((uint64)SteamFriend.UniqueNetID->GetBytes());
// Get the GameInfo from the Player via ID
FriendGameInfo_t GameInfo;
bool bIsInGame = SteamFriends()->GetFriendGamePlayed(ID, &GameInfo);
// If InGame and the GameID is actually valid, try to get the AppName
if (bIsInGame && GameInfo.m_gameID.IsValid())
{
// Request the app list before getting the app name
SteamAppList()->RequestAppList();
char NameBuffer[1024];
int NameLength = SteamAppList()->GetAppName(GameInfo.m_gameID.AppID(), NameBuffer, sizeof(NameBuffer));
if (NameLength > 0)
{
GameName = FString(UTF8_TO_TCHAR(NameBuffer));
}
Result = ESteamFriendAsyncResultSwitch::OnSuccess;
return;
}
}
Result = ESteamFriendAsyncResultSwitch::OnFailure;
}
This should ensure that the App List is up to date and increase the chances of successfully retrieving the app name with GetAppName
.