- Home /
[SCREENSHOTS]Save scenes using XML/json descriptor
Hello,
I have a concern with the game i have created and the way i load all the levels. The game is on playstore here so you can understand the concept and what i want to achieve. It is a physic game where a sheep needs to eat all the mushrooms. Each level is really simple, it contains
Some bars
Mushrooms
A sheep( the Hero )
Some Objects which move like Bombs
Moving Enemies
For the moment, When you want to Play with Level 1-1,see below what's happening:
Application.Load("level_1_1");
In each level(each scene), i have an object called LoadLevelAddictive containing a script calling Application.LoadLevelAdditive("commonObjects"); This is a scene including all the common objects between all my 45 levels like, a leaderboard , some common panel, some backgrounds
PROS to do it that way
I design all my levels using the editor.
When i am happy with a level i have created, i save it through the editor like Save As 'Level_1_2.unity'. It is really straightforward.
CONS to do it that way
I have realized this is extremely slow to load a level( like 2sec ) on a device.
When a user wants to restart the level, i use Application.Load("level_1_1"), slow, it should be instant.
I also wanted to do a level editor but since my levels are saved in a scene format, i won't be able to achieve that.
Questions:
What are the steps to migrate my existing level system ( scene based ) using json/XML descriptor ? (This look promising)
If i finally manage to save my levels in json/XML, how to design/view my levels ?
I have attached 2 screenshots so everybody will understand what is my current solution.
Level_1_1.unity.jpg is the level 1 of the world 1 of the game. This only includes what differs between each level
CommonObjects.jpg is the scene that includes all my common objects.
If someone has a solution design or some ideas, it would be greatly appreciated
(@valdelievre has P$$anonymous$$'d me to ask if UnitySerializer fits this use case)
So you certainly could use UnitySerializer to save these levels - but there are several caveats:
Unity Serializer in normal "save everything mode" does a level load at the beginning of resu$$anonymous$$g the data to get the original clean state back (obviously this is normally a pretty empty level if you are building a level designer and hence not too slow).
Anything that saves/loads individual objects has to then instantiate them on resumption and this can be costly in terms of performance
The time it takes to load a level is mostly in the setup and instantiation after the file is loaded into memory - I've yet to get a clear idea of what this is doing precisely from Unity, but if you do a LoadLevelAsync there is still usually a big pause if there is much going on with the level.
If you use Unity Serializer you would be better off using Binary mode for performance, the resulting files are not human readable (or really parsable with anything except Unity) but work as efficiently as they can without being specific to the individual project.
I'd be interested to know how many things exist in a level than takes a long time to load and whether you have any feeling for which items are impacting the performance. You can use Unity Serializer to reset individual objects for instance (without the need for it reloading the whole level, but this would be quite intricate work).
Hello $$anonymous$$ike,
Thank you very much for your answer. In a near future, i wanted to implement few things :
Faster loading between levels
I don't think UnitySerializer will help me to do that. I need to understand where is the cumbersome. What i was thinking is to put all the objects from "commonObjects" scene in one prefab. It will be slow to load the first time ( 2sec ), then i would just need to DontDestroyOnLoad this prefab each time the user change the level. What do you reckon ?
Instant level restart
I think UnitySerializer could have an important part in here. When the user want to play with level_1_1, i won't use Application.Load but rather your deserialization process. As far as i understood, UnitySerializer will load the scene level_1_1.unity automatically. What i need to do is to save each scenes using UnitySerializer ( binary, xml or whatetever your tool allows me to do ) When the end user wants to restart the level, I think it will automatically deserialize, resetting the level to his initial state, it should almost be instant. Do you agree ?
A level editor where people can create and share their own levels.
I think it will almost works like my previous point. The end-user design the levels, Press Save and it will serialize the level in a file
Your answer
![](https://koobas.hobune.stream/wayback/20220613090931im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
What are the pros and cons of ScriptableObjects vs. JSON for data files? 2 Answers
Deserializing dictionary with 'Json.Net' for Unity returns a null object. 0 Answers
Is it possible to serialize UnityEvent through reflection? 1 Answer
Parsing "complex" json 1 Answer
Best Practice for Language System 1 Answer