Unity Player Accounts Official Sample Throws Exception AuthenticationException

Is it sdk bug or example code bug?

Condition

  • Authentication 3.4.0
  • Unity 6000.0.34f1
  • Tested On: both MacOS and Windows Unity Editor

Sample Scene Name

  • UnityPlayerAccountsUIExample
  • Throws exception when click “sign in with unity” and signed in on that web page.
AuthenticationException: Invalid state for this operation. The player is already signing in.
Unity.Services.Authentication.PlayerAccounts.Samples.PlayerAccountsDemo.SignInWithUnity () (at Assets/Samples/Authentication/3.4.0/UI Example/PlayerAccountsDemo.cs:71)
UnityEngine.Debug:LogException(Exception)
Unity.Services.Authentication.PlayerAccounts.Samples.<SignInWithUnity>d__9:MoveNext() (at Assets/Samples/Authentication/3.4.0/UI Example/PlayerAccountsDemo.cs:77)
System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start(<SignInWithUnity>d__9&)
Unity.Services.Authentication.PlayerAccounts.Samples.PlayerAccountsDemo:SignInWithUnity()
Unity.Services.Authentication.PlayerAccounts.PlayerAccountServiceInternal:CompleteSignIn(SignInResponse) (at ./Library/PackageCache/com.unity.services.authentication/Player Accounts/Runtime/PlayerAccountServiceInternal.cs:264)
Unity.Services.Authentication.PlayerAccounts.<HandleSignInRequestAsync>d__60:MoveNext() (at ./Library/PackageCache/com.unity.services.authentication/Player Accounts/Runtime/PlayerAccountServiceInternal.cs:226)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult(SignInResponse)
Unity.Services.Authentication.PlayerAccounts.<SendAsync>d__15`1:MoveNext() (at ./Library/PackageCache/com.unity.services.authentication/Player Accounts/Runtime/Utilities/Network/WebRequest.cs:74)
System.Threading.Tasks.TaskCompletionSource`1:SetResult(String)
Unity.Services.Authentication.PlayerAccounts.WebRequest:RequestCompleted(TaskCompletionSource`1, Int64, Boolean, Boolean, String, String, IDictionary`2) (at ./Library/PackageCache/com.unity.services.authentication/Player Accounts/Runtime/Utilities/Network/WebRequest.cs:206)
Unity.Services.Authentication.PlayerAccounts.<>c__DisplayClass16_1:<SendAttemptAsync>b__0(AsyncOperation) (at ./Library/PackageCache/com.unity.services.authentication/Player Accounts/Runtime/Utilities/Network/WebRequest.cs:84)
UnityEngine.AsyncOperation:InvokeCompletionEvent() (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/AsyncOperation.cs:24)
class PlayerAccountsDemo : MonoBehaviour
{
        async void SignInWithUnity()
        {
            try
            {
                // THROWS EXCEPTION
                await AuthenticationService.Instance.SignInWithUnityAsync(PlayerAccountService.Instance.AccessToken);
                m_ExternalIds = GetExternalIds(AuthenticationService.Instance.PlayerInfo);
                UpdateUI();
            }
            catch (RequestFailedException ex)
            {
                Debug.LogException(ex);
                SetException(ex);
            }
        }
}
1 Like

it says the player is already signed in.

Yes. I know this is an exception caused by trying to log in duplicately when you are already logged in. However, I did not make a duplicate login. If you look at the example code and the way the official documentation describes it, the example scene should take you to a webpage when you press the “Sign In With Unity” button, and when you go through the actual sign-in process on the webpage and come back to Unity, the sign-in should be successful, the login information for that account should be displayed, and the sign-out button should be enabled. However, in this example, if I sign in on the webpage and then come back to Unity, it will always throw an exception “The player is already signing in.” And no login information is displayed.

Thanks for flagging this!

If I recall correctly from a discussion earlier this week, we found a bug in the sample for the web based Unity Player Accounts login flow. It should “work” (i.e. and sign the user in) but it displays this error because it tries to sign the user in again.

The fix should go out in the next Authentication SDK release.