Search code examples
unity-game-engineunity-webglkiicloud

System Threading Error using Kii Authentication with Unity WebGL


I'm creating a WebGL application using Unity written in C#.

I have a function that logs the user in based on an authentication token (allowing the user to skip the login screen if they've signed in previously and have a cookie).

The application works flawlessly in the Unity environment when I hit the play button. However, when I build the application and run it locally in my browser I get a "System.SystemException: Thread creation failed." error in my console log. This error seems to occur right after the user is logged in. My login function is:

public void loginWithAccessIDToken(string accessIDToken, Action<KiiUser> success)
    {  
        //Use the access token to sign-in again
        try
        {
            Debug.Log("About to log in...");

            KiiUser.LoginWithToken(accessIDToken, (KiiUser user, Exception e) =>
            {
                UnityEngine.Debug.Log("Got Something!");
                if (e != null)
                {
                    User = null;
                    success(User);
                    UnityEngine.Debug.Log("Exception caught...");
                }
                else
                {
                    User = user;
                    success(User);
                    UnityEngine.Debug.Log("Login successful...");
                }
            });
        }
        catch (Exception e)
        {
            Debug.Log("Exception caught..." + e.Message);
            success(User);
        }
    }

I have also attached a screenshot of the error I receive in Firefox below. It seems to me that Kii is doing some sort of threading. I've read online that WebGL does not support threading.. however, I do not have a good understanding of what Kii is attempting to do!

Does anyone have experience implementing this logic in their application? I'm able to keep my application running if I have exceptions enabled in the Unity build settings. Although, this is surely not a permanent solution!

If anyone has any suggestions or would like more information about my build settings please ask.

FireFox Console Log


Solution

  • The System.Threading namespace is unavailable in WebGL at the moment. Unfortunately, it sounds like this problem lies within a third party library.

    To support WebGL you can use coroutines instead of threads, but it sounds like you would have to contact the developers of Kii.