Issue with Auth when running outside of Unity editor

  • I've recent been testing a game within the Unity editor without issue, so decided to try and run it on device (Mac, iPhone and Android), however at this point anonymous auth seems to stop working with this error:

    Received an invalid json format response, check your network settings.
    GameManager:onAuthFailure(Int32, Int32, String, Object)
    BrainCloudWrapper:AuthFailureCallback(Int32, Int32, String, Object)


    public void SetupPlayer(bool tryGameCentre = false)
          if (!Bc.Client.IsAuthenticated())
              Bc.AuthenticateAnonymous(new SuccessCallback(onAuthSuccess), new      FailureCallback(onAuthFailure));
        public void onAuthFailure(int status, int errorCode, string jsonError, object sender)
        public void onAuthSuccess(string jsonResponse, object sender)
            var response = JObject.Parse(jsonResponse);
            if (response == null)
                Debug.Log("Error logging in");
            currentUser = UserModel.FromJson(response["data"].ToString());
    #if UNITY_IOS
            Debug.Log("IOS RUNNING");
            UserAuthenticationSuccessful(currentUser.SessionId != null ? true : false);

    this all works fine in the editor, it is only on device

  • Hello Gavin,
    I'm having trouble reproducing your issue to better give you a solution. What version of Unity Editor are you using? Are you properly initializing on the device before requesting authentication? I have a feeling this might be a permissions issue for network access based on the error message you received. Any other details would be helpful so that I can reproduce this error to find a solution for you.

  • Hi Franco,

    I am not sure the issue is anything to do with networking, it fully works from Unity editor and I think the error from brainCloud is potentially misleading.

    I am using Unity 2021.3.8f1

    After tracing it back tracing it back through, the error is being generated byBrainCloudComms.cs, specifically private void HandleResponseBundle(string jsonData), If I enable debugging and run on an iPhone, I get output of:

    19:22:40.664 #BCC RESPONSE - 21/04/2023 19:22:40

    The function then tries to decode the json:

    JsonResponseBundleV2 bundleObj = DeserializeJsonBundle(jsonData);

    The next bit of output is then:

    19:22:40.666 #BCC Only objects with default constructors can be deserialized. (BrainCloud.Internal.JsonResponseBundleV2)
    UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
    UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    UnityEngine.Logger:Log(LogType, Object)
    Received an invalid json format response, check your network settings.

    So data is definitely making it back from the server, but then if I log in from Unity editor, the response from BrainCloud looks similar?


  • Hello Gavin,
    Unfortunately I still cannot reproduce the error you're reporting and I've tested against all the devices you've mentioned previously. I would need more information of what your process is in your project that gives you this error that could be helpful for me to reproduce the error. Please provide any and all information or contact us at our intercom on-line chat support to provide an example project or link to project for me to work with. In the meantime I would suggest for you to check out our Authentication Example in our examples-unity repository in Github, perhaps it will provide a solution for you.
    Unity Examples:

  • Hello @Gavin-Beard!

    We've had trouble reproducing this issue on our end. After some testing with a small app on MacOS and iOS, we have not been able to see the error you are encountering using Unity 2021.3.8.

    If you could, please check out the app here and let us know if this issue is still persisting. It is a barebones authentication app and it should run on multiple devices. The Authentication.cs script has all the gory details. Just open up the Main scene under Assets > App > Misc > Main.unity to get it running. You will also need to add your brainCloud credentials, but you can copy the Authentication example template in brainCloud to test the app.

    Please let us know how this app works on your end and if any issues are encountered! You should be able to click on any error logs in the in-app console to copy the log to your device's clipboard.

    As for your specific issue, my best guess is that perhaps an external library of sorts might not be supported with brainCloud, such as the Newtonsoft Json.NET library. For JSON de/serializing, brainCloud comes with JsonFX. You can also make use of Unity's own JsonUtility for structured JSON de/serialization. Both the app I've shared and the examples on our GitHub make use of JsonFX extensively.

    If you'd like to know more and see how a more robust app can handle brainCloud authentication, as Franco suggested, you should check out our Authentication example on our Unity Examples GitHub.

    Hope this helps! Please let us know if you have further questions or inquiries about this.