Download

Using some Steam functions in C++ or blueprints (OnlineSubsystem?)

Okay so the entirety of the documentation on integrating the Steam API with a UE4 project is pretty spotty, but it seems that everyone is saying that you basically have to do nothing to make Steam work with your project. Once you add those lines to the Target.cs and Build.cs and make sure you have the DLL files, you regenerate your project files and you’re good to go.

So if that’s true, I need help here, because I’m trying to access some Steam functions and they’re not working.

Here’s a list of everything that I need from the Steam API:

  • Active player’s unique Steam ID
  • Active player’s Steam Nickname
  • Player’s friends’ Steam ID’s and aliases

I’ve seen tutorials on how to do achievements, but I cannot find anywhere where anyone access the SteamUser() or SteamFriends() functions. Whenever I do, I get an unresolved symbol error, so I include “steam_api.h”, but then I get an unresolved linker error, like it cannot find the .lib files. Once I point to those, it compiles, but the engine supposedly works without me having to manually include the libs.

Is there some OnlineSubsystem function that accesses this information for me?


Okay so I just found this piece of documentation:

https://docs.unrealengine.com/latest/INT/API/Runtime/OnlineSubsystemSteam/FOnlineSubsystemSteam/index.html

But I can’t figure out just what methods to use to get an FOnlineUser or an FOnlineFriend instance.


I see the GetIdentityInterface() method on OnlineSubsystemSteam, but I have no idea how to access it. I also see GetFriendsInterface(), but still no idea. Those have got to be the two methods I’m looking for, but I don’t know where to start with accessing the OnlineSubsystem.


Okay, so I’ve added:

#include “Online.h”
#include “Runtime/Online/OnlineSubsystemSteam/Public/OnlineSubsystemSteamPackage.h”

to my header, but I still do not have any access to FOnlineSubsystemSteam. The type is still considered undefined.

If I’m not mistaken, you’ll never need to access an FOnlineSubsystemSteam instance. Ever.
All you need to do is include and set Steam as your default online subsystem (check DefaultEngine.ini) (also check Rama’s / Unreal’s guide) and the FOnlineSubsystem interface will automatically adjust your function calls to Steam’s API.

If - however - you really want to access FOnlineSubsystemSteam, you need to include “FOnlineSubsystemSteam.h” and cast this way:



FOnlineSubsystemSteam* SteamOnlineSub = static_cast<FOnlineSubsystemSteam*>(FOnline::Get());


This is off the top of my head, might be some error here or there.

But, again, there’s no need to do this.

So you’re saying I just need to include “Online.h” and access an instance of IOnlineSubsystem?


Okay so I’ve gotten this far:

I’ve made two methods, one which attempts to get the SteamID64, and one which attempts to get the player nickname:


FString AUtilities::getSteamID()
{
	IOnlineSubsystem* ion = IOnlineSubsystem::Get();
	TSharedPtr<const FUniqueNetId> pid = ion->GetIdentityInterface()->GetUniquePlayerId(0);

	if (!pid->IsValid())
		return "Null pointer";

	return pid->GetHexEncodedString();
}

FString AUtilities::getPlayerAlias()
{
	IOnlineSubsystem* ion = IOnlineSubsystem::Get();
	FString f = ion->GetIdentityInterface()->GetPlayerNickname(0);

	return f;
}

I’ve tested these in a standalone preview and the player alias is working perfectly; however, the steamID one is giving me a value that I’m not sure of.

It returns 54EDF50A01001001, which decoded from hexadecimal is 6119816891981631489

My steamID64 is 76561198144154964. How can I get that value?


Never mind. I just found the ToString method on FUniqueNetId. Duh.

As far as i know, and i only did the Session things with Steam in C++, you can do all the things, that Subsystems share, through IOnlineSubsystem.

Which means, there are wrapper functions that do the stuff for you if you, for example, call “CreateSession”.

Things that a Subsystem has, but others not, may need to include the Steam Libs and use their functions.

For example, i have no idea if you can access the Users Profile Picture in Steam through the IOnlineSubsystem.

That’s why i tried to get it via the Steam Lib which ended in giving up, because back in that time i didn’t know how to
convert that type that Steam gave me for the Picture into something that i could use in UE4.

PS: Everything that you find out on getting general information about the Player, the Friends etc, would be very nice to have
on the Wiki. So if you have time, please write down what you learned, so others can learn from it (:

Actually, I’ve done just that. The article is here: https://wiki.unrealengine.com/Steam,_Using_Online_Subsystem

Awesome to read (: Thank you!

Oh, man. Thank you so much for making this. I was banging my head against the wall trying to find basic info on how to use these interfaces.