Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Is Signed In

Discussion in 'Authentication' started by wgeorgio, Nov 6, 2023.

  1. wgeorgio

    wgeorgio

    Joined:
    Nov 15, 2017
    Posts:
    31
    I started this code but it doesn't work. I still get "The Player is already signing in."
    Code (CSharp):
    1. bool isSignedIn = AuthenticationService.Instance.IsSignedIn;
    2. Debug.Log($"Is Signed In:{isSignedIn}");
    3.  
    4. if (!isSignedIn)
    5. {
    6.     await AuthenticationService.Instance.SignInAnonymouslyAsync();
    7. }
    Does anyone have the correct code or can tell me what I need to change?
     
  2. erickb_unity

    erickb_unity

    Unity Technologies

    Joined:
    Sep 1, 2021
    Posts:
    89
    Hello
    The most likely reason is that this code is being called multiple times
    Are you calling this from a method that is called multiple times (like a monobehaviour 'Update')?

    It likely works as expected the first time but subsequent calls happen as the original operation isn't completed and you get the error "The Player is already signing in."
     
  3. wgeorgio

    wgeorgio

    Joined:
    Nov 15, 2017
    Posts:
    31
    I get false every time I check if a user is signed in, even if it says "The player is already signed in" I have a few scripts that check if a key exists or save an object to Cloud Save and this code is in the Awake or Start methods.
     
  4. erickb_unity

    erickb_unity

    Unity Technologies

    Joined:
    Sep 1, 2021
    Posts:
    89
    Is this the only place in your project where you call the signin method?
    Is there only one instance of that monbehaviour in your scene(s)?
    Can you provide more of your sample code?
     
  5. wgeorgio

    wgeorgio

    Joined:
    Nov 15, 2017
    Posts:
    31
    So I have a cloud save script that checks if a key exists and I do this multiple times. I also do this for saving stuff to cloud save which is done multiple times.

    Code (CSharp):
    1. public async override void OnEnter()
    2. {
    3.     await UnityServices.InitializeAsync();
    4.     bool isSignedIn = AuthenticationService.Instance.IsSignedIn;
    5.     Debug.Log($"Is Signed In:{isSignedIn}");
    6.  
    7.     if (!isSignedIn)
    8.     {
    9.         await AuthenticationService.Instance.SignInAnonymouslyAsync();
    10.     }
    11. if (!key.IsNone && !key.Value.Equals(""))
    12. {
    13.     await ListAllKeys();  
    14. }
    15. }
     
  6. wgeorgio

    wgeorgio

    Joined:
    Nov 15, 2017
    Posts:
    31
    Everytime I run this
    Code (CSharp):
    1. Debug.Log($"Is Signed In:{isSignedIn}");
    this returns false.
     
  7. wgeorgio

    wgeorgio

    Joined:
    Nov 15, 2017
    Posts:
    31
    Do we have any idea why this isn't working ^^^ @erickb_unity
     
  8. erickb_unity

    erickb_unity

    Unity Technologies

    Joined:
    Sep 1, 2021
    Posts:
    89
    I'm not sure why this isn't working, you should see error logs if any of the operations failed

    Seeing how and where this function is called would also help