Inviting / joining steam friends

Hello everyone,

I’m looking in to how to invite and join others through your steam friends list.
I couldn’t find any information on how to do this in Blueprints.

Hope someone can help me,
Thank you.

Hi, from steamwork sdk isteamfriends.h i found this

// Requests rich presence for a specific user.
virtual void RequestFriendRichPresence( CSteamID steamIDFriend ) = 0;

// rich invite support
// if the target accepts the invite, the pchConnectString gets added to the command-line for launching the game
// if the game is already running, a GameRichPresenceJoinRequested_t callback is posted containing the connect string
// invites can only be sent to friends
virtual bool InviteUserToGame( CSteamID steamIDFriend, const char *pchConnectString ) = 0;

so i guess UE4 should use GameRichPresenceJoinRequested_t callback to work with friend invites

in spacewar example game there’s

// callback for when the lobby game server has started
STEAM_CALLBACK( CSpaceWarClient, OnLobbyGameCreated, LobbyGameCreated_t, m_LobbyGameCreated );
STEAM_CALLBACK( CSpaceWarClient, OnGameJoinRequested, GameRichPresenceJoinRequested_t, m_GameJoinRequested );
STEAM_CALLBACK( CSpaceWarClient, OnAvatarImageLoaded, AvatarImageLoaded_t, m_AvatarImageLoadedCreated );

in UE4 source code there’s

void FOnlineAsyncTaskManagerSteam::OnInviteAccepted(GameRichPresenceJoinRequested_t* CallbackData)
{
FOnlineAsyncEventSteamInviteAccepted* NewEvent =
new FOnlineAsyncEventSteamInviteAccepted(SteamSubsystem, FUniqueNetIdSteam(CallbackData->m_steamIDFriend), UTF8_TO_TCHAR(CallbackData->m_rgchConnect));
UE_LOG_ONLINE(Verbose, TEXT(“%s”), *NewEvent->ToString());
AddToOutQueue(NewEvent);
}

STEAM_CALLBACK(FOnlineAsyncTaskManagerSteam, OnInviteAccepted, GameRichPresenceJoinRequested_t, OnInviteAcceptedCallback);

but in UE4 editor i can’t find OnInviteAccepted in blueprints (without contex sensetivity ofc), also i don’t see any friend events when open blueprints functions in context menu without contex sensetivity, there’s only few of them under “online”:

also i searched in blueprints with words: invit, friend, task, rich - nothing interesting were found

also looked into

void FOnlineAsyncTaskManager::AddToOutQueue(FOnlineAsyncItem* CompletedItem)
{
FScopeLock Lock(&OutQueueLock);
OutQueue.Add(CompletedItem);
}

but it doesn’t give me an idea how UE4 engine designed to tell blueprints something

this isn’t anwer to your question, but hope may help you or other dig deeper

Thank you for these insights, this might help me a bit. I still hope someone from the staff will be able to give a bit more information on the Blueprint functions for this.

in case steam already linked into engine maybe it’s possible to handle these functions from C++ custom classes and make your own interface to blueprints

i din’t try this yet, but think there should be some C++ functions/methods to get reference on current exist FOnlineAsyncTaskManagerSteam class instance, maybe it’s globally stored somewhere, guess Rama may know

That can’t be done in Blueprints,

You can expose those from C++ though but that will require some work.

Check OnlineSessionInterface.h out, it has all the functions you need, the function to invite a friend is

virtual bool SendSessionInviteToFriends(...);*

For answering to an invite, you’ll need to check the OnSessionInviteAccepted Delegate. I have successfully set up and worked with those but it’s not exactly well explained. Some info can be found on how to use them in ShooterGame example code.

You can access to the interface with the line

IOnlineSubsystem* OnlineSubsystem = IOnlineSubsystem::Get();

From there, you should be able to access a wide variety of options. If you have an IDE correctly set up and if you are a decent programmer this should get you started.

Can’t give you my code unfortunately :slight_smile:
Good luck !

This is probably overkill for what the user originally requested.

 virtual bool InviteUserToGame( CSteamID steamIDFriend, const char* pchConnectString ) = 0;

is basically the UE-Steam interface which you can access of course but has already been linked through the OnlineSessionInterface, it’s easier to use OnlineSessionInterface because it will return the correct interface (if you’re playing on PS4, you’ll use PSN for instance).

I’m giving hints on how to set it up correctly in my post

Since people don’t seem to like my post, i’ll hint a bit more …

The right way to set it up is to use the IOnlineSubsystem wich will give you a correct pointer to the currently used Interface.

hence for instance, to set up a Callback that will be called whenever you receive a Steam Invite and you’re in-game

IOnlineSubsystem* OnlineSub = IOnlineSubsystem::Get(); 
// Retrieve our Interface
if (OnlineSub) // if an Online Interface is valid
{
	IOnlineSessionPtr SessionInt = OnlineSub->GetSessionInterface();
	// Get the Session Interface Pointer
	FOnSessionInviteAcceptedDelegate OnSessionInviteAcceptedDelegate = FOnSessionInviteAcceptedDelegate::CreateUObject(this, &MyClass:MyCallbackFunction); 
	// Create a Delegate For Session Invite Acceptance. 
	//This will trigger our function Whenever we accept an Invite 
	SessionInt->AddOnSessionInviteAcceptedDelegate_Handle(0, OnSessionInviteAcceptedDelegate); 
	// Bind the Delegate
}

The Delegate Method Should have the following signature

MyCallbackFunction(int32 LocalUserNum, bool bWasSuccessful, const FOnlineSessionSearchResult & SessionToJoin)

from FOnlineSessionSearchResult you can use GameSession to Join a Game

i’m not so expirienced in C++ and how UE4 built, seems you know it better ^^

Thank you all for your help.
I’ll have to dive into C++ and hope I can figure this out :slight_smile:

Sorry to resurrect this answer back from the dead. But I noticed in Steamworks 138 in the SpaceWarsClient.h example that the STEAM_CALLBACKS() is changed to

      STEAM_CALLBACK( CSpaceWarClient, OnLobbyGameCreated, LobbyGameCreated_t );

cutting out the last member parameter m_LobbyGameCreated.

But I can’t compile my code either wait. Without the member I get

error C4003: not enough actual parameters for macro ‘STEAM_CALLBACK’

And I also get

error C2208: ‘CCallback’: no members defined using this type

But if I add the member to the STEAM_CALLBACK macro, then I get the error:

Error C2512: ‘CCallback’: no appropriate default constructor available

I am stucked either way. I am using Steamworks 132 in the Engine 4.14

You can do this in blueprints: UE4 Tutorial | Steam Friends | Inviting and Accepting Requests - YouTube