When to load 700 questions for a trivia game quiz

Hi there,

I’m making a trivia game and all my questions are in XML files: Level1.xml, level2.xml, etc. I have 2 scenes in my game:

First one is the level selection, that tells for each level how much question is left to answer

Second one is the actual game, that loads all questions from 1 level in particular and play them for the player.

My problem is that my game takes a lot of time for loading everything. Currently, I’ve put all my xmls in prefab objects like this:

This “Level” object is a container that is in the 2 scenes. As you can imagine, my level selection takes 30 seconds to load.

So I’m trying to find a better way to load only what I need : for the game itself I could resource load only the level I need, but for the level selection, I need all the progress of the player so I guess I need all questions size of all levels to do so.

Any best practice/ideas?

Thanks,

A few thousand lines in an XML file should load very quickly, probably dealing with fractions of a second. In my game it loads and processes hundreds of thousands of lines from csv files in under 2 seconds. Have you used the Profiler during this process to see what Unity sees as taking the bulk of that 30 seconds? Does each entry in the XML kick off some additional processing of the data?

I notice a GameObject called “MusicSource”. Does it happen to reference several large music audio clips? I’ve personally seen large audio clips as a source of scenes taking a long time to load. If this is the actual source of the lag, set all of the audio clips to load in background, except the first music file you want playing when the scene loads (so it will start playing when expected to).

1 Like

Why not store the player’s progress separately, say in its own “Player.xml” file, which would contain the last level and question passed?

Then you’d only need to read these two values to determine which levels/questions the player has access to and enable their corresponding UI menu options in the game.
You could then load each level/question XML file separately for each level/question the user is currently on in the application.

1 Like

Well this is what I do for the player progress. My problem is that on the level side I’m writing : You have passed X questions of Y total.

X is easy to get with your method, I actually need the Y, which is contained in my XML file, so I need to read it in the end to give this Y value, which is the problem.

Any reason you couldn’t store Y right next to X just for the sake of speed and quick access?

When the game first ever loads, player hasn’t start playing so X = 0. But Y = 120 (120 questions for the first level). So I should write : 0 questions out of 120.

And this for all levels on my level selection scene…

I have the feeling I need to hardcode all values for each level (level1 = 120 questions, level2 = 110 questions, etc.) , but tat sounds really silly if I ever want to add or remove questions, my code should calculate it.

Actually it’s not XML files, sorry for missing that part: it is objects that are built from the XML. One question looks like this:

6914756--810881--upload_2021-3-8_23-20-35.png

I think the loading time is because of the images for each question that are texture resources.

That would be an excellent hypothesis. You could prove it with the Window → Analysis → Profiler

You might get a lot of benefit by making an editor script that scans all the XML questions and builds a quick index so you can go get precisely the next one you want.

That way you could:

  1. only load one at a time

  2. always know how many there are