Unreal Engine Module - Login with Steam - Put it all together
Connecting UI With Login Implementation
In this section, you will learn how to connect the W_SinglePlatformAuthWidget_Starter
widget to perform login with Steam using the AuthEssentialsSubsystem_Starter
subsystem.
Open the
SinglePlatformAuthWidget_Starter
class CPP file and add the following code to theOnLoginWithSinglePlatformAuthButtonClicked()
function.void USinglePlatformAuthWidget_Starter::OnLoginWithSinglePlatformAuthButtonClicked()
{
...
// Use Auth Essentials's starter files for login if starter mode is active.
else
{
// Grab the login widget reference to show login state UI.
ULoginWidget_Starter* LoginWidget_Starter = Cast<ULoginWidget_Starter>(ParentWidget);
ensure(LoginWidget_Starter);
LoginWidget_Starter->SetLoginState(ELoginState::LoggingIn);
LoginWidget_Starter->OnRetryLoginDelegate.AddUObject(this, &ThisClass::OnLoginWithSinglePlatformAuthButtonClicked);
UAuthEssentialsSubsystem_Starter* AuthSubsystem_Starter = GetGameInstance()->GetSubsystem<UAuthEssentialsSubsystem_Starter>();
ensure(AuthSubsystem_Starter);
// Login with single platform auth is considered as login with default native platform.
// Thus, it doesn't need username, token, nor the login method.
AuthSubsystem_Starter->SetAuthCredentials(EAccelByteLoginType::None, TEXT(""), TEXT(""));
AuthSubsystem_Starter->Login(GetOwningPlayer(), FAuthOnLoginCompleteDelegate_Starter::CreateUObject(LoginWidget_Starter, & ULoginWidget_Starter::OnLoginComplete));
}
}Now, when you press the login with Steam button, it will perform login with Steam via the
UAuthEssentialsSubsystem_Starter
subsystem. The callback will be handled by its parent widget which is theW_Login_Starter
to direct the player to the Main Menu if the login is successful or showing an error message if fails. You can check the source code from the Module: Login with Device ID module.Congratulations! Your Steam login implementation is complete.
Resources
- The files used in this tutorial section are available in the Byte Wars GitHub repository.
- AccelByteWars/Source/AccelByteWars/TutorialModules/Access/SteamAuthentication/UI/SinglePlatformAuthWidget_Starter.h
- AccelByteWars/Source/AccelByteWars/TutorialModules/Access/SteamAuthentication/UI/SinglePlatformAuthWidget_Starter.cpp
- AccelByteWars/Source/AccelByteWars/TutorialModules/Access/AuthEssentials/AuthEssentialsSubsystem_Starter.h
- AccelByteWars/Source/AccelByteWars/TutorialModules/Access/AuthEssentials/AuthEssentialsSubsystem_Starter.cpp