Download

Issue Getting Steam UID

I need the Steam ID for persistance of character through the Database. I built a C++ FunctionLibrary for blueprint use but it gives me my local computer name. Even if i create a session it stays the same. I did a bunch of searching and either solutions i found didnt work or got me only to this step.

6e56b06e4bc7bd52fbbe9a3cb7d0fa2d48305ba5.jpeg



FString UMyServerBlueprintLibrary::GetSteamID(APlayerController* PlayerController) {

	FString ID = "";

	if (!PlayerController) return "Error";
	if (!PlayerController->PlayerState) return "error";

	ID = PlayerController->PlayerState->UniqueId->ToString();

	return ID;
}


PayerState->PlayerId

That gives me a tiny number… 256 on first run then when i create a session it increments to 257 but not the actual steam ID.



FString UMyServerBlueprintLibrary::GetSteamID(APlayerController* PlayerController) {

	FString ID = "";
	int PUID = 0;

	

	if (!PlayerController) return "Error";
	if (!PlayerController->PlayerState) return "error";

	PUID = PlayerController->PlayerState->PlayerId;
	ID = FString::FromInt(PUID);

	return ID;

}


Connected to Steam as the Dev App

New ID:
c82ecdeaee.jpg

Cant Get any sort of connection to Steam API Functions in VS either…

CSteamID uid = SteamUser()->GetSteamID(); has CSteamID, SteamUser() and GetSteamID() As Unidentified…

Oh you want the Steam account ID; I don’t know how to get that, don’t even know if Valve allow you to read that.
I’d check Steam SDK and try to find some light

they must allow it… games like Arl use it for their account system as well.

SteamUser()->GetSteamID()->ConvertToUint64();
should do it

would love to use it except SteamUser() is undefined it says and wont compile. Apparently even though steam is running i need to do something to actually get access to the API?

You get just an undefined or unresolved externals? For both cases, try including **“ThirdParty/Steamworks/Steamv132/sdk/public/steam/steam_api.h” **in your main game header file or somewhere else. Also make sure you added Steamworks to the build rules, so your build file should look something like this:



public class Steam : ModuleRules
{
	public Steam(TargetInfo Target)
	{
		PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore" });

        //Steam stuff here
        PublicDependencyModuleNames.AddRange(new string] {
            "OnlineSubsystem",
            "OnlineSubsystemUtils",
            "Steamworks"
        });


        DynamicallyLoadedModuleNames.Add("OnlineSubsystemSteam");


        PrivateDependencyModuleNames.AddRange(new string] {  });




thank you mine was missing “steamworks” added it to look like this:



// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;

public class MGame : ModuleRules
{
    public MGame(TargetInfo Target)
    {
        
        MinFilesUsingPrecompiledHeaderOverride = 1;
        bFasterWithoutUnity = true;
        
        PublicDependencyModuleNames.AddRange(
            new string] { 
                "Core",
                "CoreUObject",
                "Engine",
                "InputCore",
                "RHI",
                "UMG", "Slate", "SlateCore"
            }
        );
        
        PublicDependencyModuleNames.AddRange(new string] { 
            "OnlineSubsystem",
            "OnlineSubsystemUtils",
            "Steamworks"
        });
        
        DynamicallyLoadedModuleNames.Add("OnlineSubsystemSteam");
    }
}


Added the .h you gave me to the top of my blueprintlibrary .cpp file and BAM no more issues, i love you! now to figure out the rest of what i need to do :slight_smile:

Glad I could help! I had the same problem as you a month ago and i couldn’t find help so the future can read this :smiley: i also made a Wiki entry about the Steam Workshop, if you need something like this:

So, not to push the luck too far, i have a unique id seemingly appearing but it doesnt in any way match my Steam UID. Using Code:



FString UMyServerBlueprintLibrary::GetSteamID(APlayerController* PlayerController) {

	FString ID = "";
	int PUID = 0;
	
	if (!PlayerController) return "Error";
	if (!PlayerController->PlayerState) return "error";

	if (SteamUser() == nullptr)
		return "None";

	CSteamID uid = SteamUser()->GetSteamID();
	uint64 pid = uid.ConvertToUint64();

	ID = FString::FromInt(pid); 
	return ID;
}

It gives me a number that is no where near long enough nor starts with the right digits.

a422302501d28728066ca5b9a7152c13213e4152.jpeg Any ideas on this?

The odd thing is if i find my UID through a steamid finder it shows that number as the number CS:S would use…
according to what i can find this is a “Legacy ID”.

And now magically after changing nothing i get a nullptr from the steamuser(). No matter what i do its like steam isnt even running anymore. It was working fine last night, o started working on the DB connection and need the UID to check for existing players or not and the UID is nullptr now…

Do you see the overlay? Note that its not working in the editor.

yea its wierd, magiacally its working again… maybe a ue4 glitch? lol. this is in standalone with the overlay displayed. Didnt work for a good while, then like magic it started working again…

Hmm I think Steam is the problem… Sometimes it does not initialize, but if you go for production, it should work as expected

thanks again.

Think im going to have to drop steam for now… nullptr yet again, 2 days straight this time, restarting steam or computer not fixing anything. not initializing again :frowning:

Hmm, strange. It means that steam is not ready, but if you see the overlay, Unreal fails some way to init Steam. Try wrapping your whole code inside



if (SteamAPI_Init())
{
  //your ID getting
}
else
{
  //you have a Problem
}


Now this 1. looks if steamAPI is initialized, and 2. inits it when not. I hope this works!

nevermind, foudn the issue i think. dont knwo why it would of worked at all now that i think about it. The intermittent thing had me thrown for a loop. it was checking a steam user before init… stupid mistake on my part.



	if (SteamAPI_Init()) {

		if (SteamUser() == nullptr)
			return "nullptr";

		CSteamID steamID = SteamUser()->GetSteamID();

		uint64 Return = steamID.CSteamID::ConvertToUint64();

		//Return ID as String if Found
		return FString::FromInt(Return);
	}

	return "Unknown";
}


Fixed it by putting the null pointer check inside the if(SteamAPI_Init())