After adding SteamWorks integration in your project you can go ahead and authenticate the player. If successful, this call will return a lot of data that you can use to display to the Player or make more calls to LootLocker during this session.
We'll start by creating a new empty Game Object in your scene and calling it GameManager. Feel free to skip this if you already have a GameManager or similar in your game.
In this new GameObject you can add a new script called GameManager.
Open up your new script in your editor of choice and add the following code:
usingLootLocker.Requests;usingSteamworks;usingSystem;usingSystem.Collections;usingSystem.Collections.Generic;usingSystem.Text;usingUnityEngine;publicclassNewBehaviourScript:MonoBehaviour{voidStart() { // To make sure Steamworks.NET is initializedif (!SteamManager.Initialized) {return; }var ticket =newbyte[1024];var networkIdentity =newSteamNetworkingIdentity();var newTicket =SteamUser.GetAuthSessionTicket(ticket,1024,outuint ticketSize,ref networkIdentity);CSteamID SteamID =SteamUser.GetSteamID();LootLockerSDKManager.VerifyPlayerAndStartSteamSession(SteamID.ToString(),ref ticket, ticketSize, (response) => {if (!response.success) {Debug.Log("Error starting a LootLocker session from the Steam User: "+response.errorData.ToString());return; }Debug.Log("Successfully started a LootLocker session from Steam User with ID: "+SteamID.ToString()); });}
Retrieve the Steam Session Ticket
The following steps will help you to retrieve the SteamSessionTicket and SteamId64 from the Online Subsystem that you set up in the previous step.
Create a new UClass called USteamSessionHelper like this (this is the .h file):
// Copyright (c) 2021 LootLocker#include"SteamSessionHelper.h"#include"Interfaces/OnlineIdentityInterface.h"#include"OnlineSubsystem.h"FString USteamSessionHelper::GetSteamSessionTicket(int LocalUserNumber){const IOnlineSubsystem* OnlineSubsystem = IOnlineSubsystem::Get(STEAM_SUBSYSTEM);if (OnlineSubsystem ==nullptr||OnlineSubsystem->GetSubsystemName() != STEAM_SUBSYSTEM) { //Handle error: "Could not get Steam Online Subsystem"return""; }const IOnlineIdentityPtr IdentityInterface =OnlineSubsystem->GetIdentityInterface();if (IdentityInterface ==nullptr||!IdentityInterface.IsValid()) { //Handle error: "Could not get Steam Online Subsystem Identity Interface"return""; }if(IdentityInterface->GetLoginStatus(LocalUserNumber) != ELoginStatus::LoggedIn) { //Handle error: "Player is not logged in"return""; }returnIdentityInterface->GetAuthToken(LocalUserNumber);}FString USteamSessionHelper::GetSteamId64(int LocalUserNumber){const IOnlineSubsystem* OnlineSubsystem = IOnlineSubsystem::Get(STEAM_SUBSYSTEM);if (OnlineSubsystem ==nullptr||OnlineSubsystem->GetSubsystemName() != STEAM_SUBSYSTEM) { //Handle error: "Could not get Steam Online Subsystem"return""; }const IOnlineIdentityPtr IdentityInterface =OnlineSubsystem->GetIdentityInterface();if (IdentityInterface ==nullptr||!IdentityInterface.IsValid()) { //Handle error: "Could not get Steam Online Subsystem Identity Interface"return""; }if(IdentityInterface->GetLoginStatus(LocalUserNumber) != ELoginStatus::LoggedIn) { //Handle error: "Player is not logged in"return""; }const TSharedPtr<const FUniqueNetId> UniqueIdPtr =IdentityInterface->GetUniquePlayerId(LocalUserNumber);if (!UniqueIdPtr.IsValid()) { //Handle error: "Could not get Steam Player ID"return""; }returnUniqueIdPtr->ToString();}
Generate Visual Studio project files and build the project.
You can now use these new methods to get the Steam id and Steam session ticket from either blueprints or code.
Verify the Player and Start a LootLocker session
In Blueprint you can retrieve the token and SteamId64 by finding the nodes you just made above: GetSteamSessionTicket and GetSteamId64 in the LootLocker | SteamSessionHelper category. This is static so you can find it by right-clicking anywhere within the Event Graph.
Then you can pass the SteamSessionTicket( and the SteamId64 (the result of those nodes) to the Verify Player and Start Steam Session node which you can find by right-clicking anywhere within the Event Graph.
To copy and paste the above example into your editor, look here.
Input
You need to exchange the TriggerSteamAuthentication event for whatever event you want to use to trigger the login flow.
This example does not include the nodes you made above to get the steam id and session ticket. So make sure to utilize those if you made them. If you're getting the values another way, then that's fine. Simply plug the values into the Verify Player and Start Steam Session node.
Output
We recommend branching the completed events on the success flag, and if you do this you will probably want to add error handling in case the request fails as well as what (if any) continued actions you want on success.
The session response on a successful call also contains a lot of interesting information that you likely want to save, such as player_id, public_uid, and player_ulid among others.
You can not test authentication with Steam in the editor. You need to package your game before it can connect to Steam.
Congratulations - you have now started using LootLocker in your game with Steam! Next up we suggest you look at our feature set, and decide which ones you want to use in your game.