メインコンテンツまでスキップ

Unreal Engine Module - Login with Steam - Put it all together

Last updated on January 13, 2024

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.

  1. Open the SinglePlatformAuthWidget_Starter class CPP file and add the following code to the OnLoginWithSinglePlatformAuthButtonClicked() 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));
    }
    }
  2. 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 the W_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.

  3. Congratulations! Your Steam login implementation is complete.

Resources