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.
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).
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.
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.
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.
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.