How to get player steam id?

We’re making a multiplayer online game with a persistent world.
Every player can create multiple characters and play with them, so we need to store players info to know who is who.
As we’ll be using SteamAPI for authorization and multiplayer servers, we would like to know how we can, from the server, obtain the player Steam ID.
We cant find any variable or method in docs to get the Steam ID.

1 Like

If you use the SteamSubsystem, the PlayerID will be the SteamID. You can find the PlayerID in the PlayerState.

But PlayerID is an integer, it’s giving me the value “256” no matter what account I use. How can it be the SteamID (STEAM_X:X:XXXXXX)?

PS: I posted in the wrong section, can you move this to the C++ forum? Thank you

Hm, this is odd. I just googled a bit and i can’t seem to find any information on how to get the ID.

Rama tried something in the Beta version of the Engine but the question about getting the ID wasn’t really answered.

Maybe write him a PM and ask him about it. (:

This most likely means you are not actually using the Steam Online Subsystem

Make sure you have your DefaultEngine.ini setup correctly!

Always check out the latest version of ShooterGame/Config/DefaultEngine.ini to see what you need for Steam as the engine evolves.

I have this wiki on the subject of Steam Integration
https://wiki.unrealengine.com/Steam,_Using_the_Steam_SDK_During_Development

:slight_smile:

Rama

PS: There are other ways to get Steam ID that are more complicated, but let know if the above helps.

Thank you Rama, I’ll try it tonight and post here the results

I made the setup again from scratch using 4.7.1. Everything is configured following your wiki and checking the ShooterGame/Config/DefaultEngine.ini and it’s not working.
I get the steam screen overlay when pressing SHIFT+TAB
I’m printing the PlayerState->PlayerId using GEngine->AddOnScreenDebugMessage.
If I run the game as standalone it prints “256”.
If I run the game in a new editor window using run dedicated server it prints “0” and the editor hangs and stops responding.

My DefaultEditor.ini file:




[/Script/HardwareTargeting.HardwareTargetingSettings]
TargetedHardwareClass=Desktop
AppliedTargetedHardwareClass=Desktop
DefaultGraphicsPerformance=Maximum
AppliedDefaultGraphicsPerformance=Maximum

[/Script/WindowsTargetPlatform.WindowsTargetSettings]
+TargetedRHIs=PCD3D_SM5
+TargetedRHIs=PCD3D_SM4

[/Script/Engine.GameEngine]
!NetDriverDefinitions=ClearArray
;+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="/Script/OnlineSubsystemSteam.SteamNetDriver",DriverClassNameFallback="/Script/OnlineSubsystemUtils.IpNetDriver")
+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemSteam.SteamNetDriver",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver")

[OnlineSubsystem]
DefaultPlatformService=Steam
PollingIntervalInMs=20
 
[OnlineSubsystemSteam]
bEnabled=true
SteamDevAppId=480
GameServerQueryPort=27015
bRelaunchInSteam=false
GameVersion=1.0.0.0
bVACEnabled=1
bAllowP2PPacketRelay=true
P2PConnectionTimeout=90

[/Script/OnlineSubsystemSteam.SteamNetDriver]
NetConnectionClassName="OnlineSubsystemSteam.SteamNetConnection"
AllowDownloads=false

[/Script/Engine.RendererSettings]
r.MobileHDR=True
r.AllowOcclusionQueries=True
r.MinScreenRadiusForLights=0.030000
r.MinScreenRadiusForDepthPrepass=0.030000
r.PrecomputedVisibilityWarning=False
r.TextureStreaming=True
Compat.UseDXT5NormalMaps=False
r.AllowStaticLighting=True
r.NormalMapsForStaticLighting=False
r.GBuffer=True
r.GenerateMeshDistanceFields=False
r.Shadow.DistanceFieldPenumbraSize=0.050000
r.TessellationAdaptivePixelsPerTriangle=48.000000
r.SeparateTranslucency=True
r.CustomDepth=1
r.DefaultFeature.Bloom=True
r.DefaultFeature.AmbientOcclusion=True
r.DefaultFeature.AmbientOcclusionStaticFraction=True
r.DefaultFeature.AutoExposure=True
r.DefaultFeature.MotionBlur=True
r.DefaultFeature.LensFlare=True
r.DefaultFeature.AntiAliasing=2
r.EarlyZPass=3
r.EarlyZPassMovable=False
r.DBuffer=False
r.ClearSceneMethod=1
r.MSAA.CompositingSampleCount=4
r.WireframeCullThreshold=5.000000
UIScaleRule=ShortestSide
UIScaleCurve=(EditorCurveData=(Keys=),ExternalCurve=None)

[/Script/Engine.UserInterfaceSettings]
UIScaleCurve=(EditorCurveData=(Keys=((Time=480,Value=0.444),(Time=720,Value=0.666),(Time=1080,Value=1.0),(Time=8640,Value=8.0))),ExternalCurve=None)
UIScaleCurve=(EditorCurveData=(Keys=((Time=480.000000,Value=1.000000),(Time=745.200012,Value=1.000000),(Time=947.260803,Value=1.000000),(Time=8640.000000,Value=1.000000))),ExternalCurve=None)

[/Script/EngineSettings.GameMapsSettings]
EditorStartupMap=/Engine/Maps/Templates/Template_Default
EditorStartupMap=/Game/Maps/World
TransitionMap=
bUseSplitscreen=True
TwoPlayerSplitscreenLayout=Horizontal
ThreePlayerSplitscreenLayout=FavorTop
GameDefaultMap=/Engine/Maps/Entry
GameDefaultMap=/Game/Maps/EntryLevel
ServerDefaultMap=/Engine/Maps/Entry
ServerDefaultMap=/Game/Maps/World
GlobalDefaultGameMode=/Script/Engine.GameMode
GlobalDefaultGameMode=/Script/SoulnetServer.WorldGameMode
GlobalDefaultServerGameMode=None


The 0 ID is one thing, but could you post the log that’s saved when the editor crashes on Pastebin or something similar?

Sorry, it just hangs and stops responding

I am pretty sure the PlayerId is not the SteamID.
The SteamID is a 64bit unsigned integer (unsigned long long), however the PlayerId is a 32bit signed integer.


UPROPERTY(Replicated, BlueprintReadOnly, Category=PlayerState)
int32 PlayerId

To get the “STEAM_X:X:XXXXXX” format first you have to get the 64bit format.

The UniqueID has some access to the steamid, but the steamid itself seems to be hidden.



UPROPERTY(ReplicatedUsing=OnRep_UniqueId)
FUniqueNetIdRepl UniqueId

I hope it helps.

I thought that in order to use the steam subsystem you needed to have an ID for your game, which according to steam means you must have a project that has been greenlighted. Is this not the case?

You don’t need to have an approved game on steam. If you want to work with the SDK (test your game for example) you can use a test AppID.

Greenlight FAQ:

Have a look at the SDK documentation:
https://partner.steamgames.com/documentation/

But i wouldn’t worry about the steam integration if my game is not approved just yet.

The steamuserID is contained inside a CSteamID which has a function to convert it to a usable 64-bit Uint.

Nice, but I need the steam id to identify players in a persistent world storing a custom id and the steam id in a database. I think the UniqueId may change every time the user plays the game right?

No a Steam ID is unique / steam account and it will not change. To identify a player use: FUniqueNetIdRepl / FUniqueNetIdSteam. So the UniqueId will give you the SteamID.
I think it has a ToString method according to the code it returns a 64bit integer in an FString. Convert it back to uint64_t then you can use it for database queries.

GitHub Code:
https://github.com/EpicGames/UnrealEngine/blob/c9f4efe690de8b3b72a11223865c623ca0ee7086/Engine/Source/Runtime/Online/OnlineSubsystemSteam/Private/OnlineSubsystemSteamTypes.h

Thank you very much Azarus, I got it working perfectly fine!

Thank you Azarus. One question. It’s possible to expose FUniqueNetIdSteam on blueprints? Maybe with a subclass of PlayerState?

What you can do is to use the 32 bit version or use the new SteamID3 version, or use the the 64 bit ID as an FString. You can convert between those versions. Exposing it as a string in blueprints should be enough for any task.

Yeah thanks, but i don’t know where to start, i’m not a c++ developer.
However in the engine source i can find some calls to


ISteamUser* SteamUserPtr = SteamUser();
return SteamUserPtr && SteamUserPtr->GetSteamID();

or like in PlayerState


UniqueId.GetUniqueNetId();

But i can’t understand what i should do to go forward

Why isn’t the PlayerID inside of the PlayerState enough? It should contain the SteamID: