0

I have completed the Unity Quiz tutorial:

https://www.youtube.com/playlist?list=PLX2vGYjWbI0QvcZNfQaJ3efswYoDmaQWX

With intent of using it as a basis for an Android Quiz game using mechanics similar to that of tinder/reigns where you will swipe Right or left for an answer being true or false.

This tutorial uses a json file to store Question and Answer data, which works successfully within the unity editor however does not work when deploying the game to an Android device.

I need some help resolving this issue so that my game can load the questions and answers successfully from an android device.

I am open to suggestions using an alternative method to json for storing this data, Any help resolving this would be appreciated.

I have done background research and I understand that using json in Android is difficult due to the StreamingAssets folder being zipped. This can be overcame through the WWW feature in unity, I believe, but I dont quite understand it.

I found someone with a similar problem in this feed here, but the answer is not very clear at all. If you are able to understand how their problem was resolved, it would be great if you could explain.

In Unity, how can I populate this allRoundData array from a json file in a way that works on Android?

All of the code can be found on the Unity website here: https://unity3d.com/learn/tutorials/topics/scripting/question-and-answer

But the main bit is within the DataController class with the Load function.

private void LoadGameData()
    {
        string filePath = Path.Combine(Application.streamingAssetsPath, gameDataFileName);

        if (File.Exists(filePath))
        {
            string dataAsJson = File.ReadAllText(filePath);
            GameData loadedData = JsonUtility.FromJson<GameData>(dataAsJson);

            allRoundData = loadedData.allRoundData;
        }
        else
        {
            Debug.LogError("Cannot load game data");
        }
    }

Would really appreciate any help in getting this working within android. I know this is kind of a duplicate question however I don't feel it has been resolved in a way that is easy to comprehend for beginners.

Thanks again.

Greg
  • 1
  • 1
    Hi Greg, welcome to SO.. um, its not exactly clear what specifically you are stuck on, as you have already identified that this is answered somewhere else, its likely to be closed. – BugFinder Mar 29 '19 at 17:56
  • Hi there, Thanks for the quick reply. I just think that the resolution I attached doesn't explain exactly what was changed and only includes the final function they added.I just dont understadn in the context of the tutorial how they changed the json file into a text file. – Greg Mar 29 '19 at 18:08
  • I would just like help understanding what steps I would need to take to get the data to load on android. Using the code in the attached issue would be great but I just need a bit of help making sure its all set up correctly. Thanks again. – Greg Mar 29 '19 at 18:17
  • Is your issue the lack of an entitlement/permission to read from the filesystem? – David Hoelzer Mar 29 '19 at 18:26
  • I am not sure exactly, when I run the quiz in unity everything runs perfect with all the Questions appearing as expected. But when deployed to the Android device this isn't the case. I believe from what Ive read this is to do with Android compressing the data making it inaccessible. – Greg Mar 29 '19 at 18:34
  • @Greg you do know json is only text anyway right? – BugFinder Mar 29 '19 at 18:36
  • Yeah, Sorry I think my title reads wrong. – Greg Mar 29 '19 at 18:38
  • Do you think a better method for android is just using an alternative to json? – Greg Mar 29 '19 at 18:40

0 Answers0