- Home /
LoadLevelAsync progress doesn't include Awake() of the next scene
Hey,
I am working on making a transition scene and I need help.
On the menu scene, Play button do the loadSceneAsync with a transition (or a loading bar, I tried both ways).
The load bar finishes as the LoadSceneAsync is "isDone ", otherwise it shows the progress (slider tutorial..you know the standard way).
My issue is that the game freezes before showing the next scene and I don't know what to do. Important information: The Awake() method of the next scene serialize an xml file into a class, and this what causes the freeze.
The Awake method:
InitializeServices();
Within the InitializeServices, there is this line:
using (StringReader reader = new StringReader(xmlWTF))
{
this.WordTreeFreqNode = (WordTreeFrequencyNode)xs.Deserialize(reader);
}
xmlWTF is a path to a xml file. This line reads a file and deserialize it: it is always the same file content to deserialize each time. This line is what make the game "freezes". The deserialization is however necessary.
Do you know how to do in these situations? What are the best practice?
Is there a way to include Awake() of the next scene into progression?
Thanks
Answer by FrameXdropProvrex · Jun 17, 2020 at 06:01 PM
A rule of thumb is to only use Awake to initialize the script and communicate within the script while the Start method is used to communicate with other scripts. If the Awake method doesn't communicate with other scripts i don't know what the problem is. Maybe sharing the part of the awake method will give more insight.
Can you show me the part where you create the XmlSerializer (xs)?
Are you creating a new XmlSerializer before deserializing the file? Because then there's no reason to hardcast it to WordTreeFreqNode.
XmlSerializer xs = new XmlSerializer(typeof(WordTreeFreqNode));
this.WordTreeFreqNode = xs.Deserialize(reader);
I don't know for sure, but hardcasting can cause problems from time to time and is best to be avoided.
//Here we are just going to deserialize the X$$anonymous$$L where the Word Tree Frequency was generated
XmlSerializer xs = new XmlSerializer(typeof(WordTreeFrequencyNode));
using (StringReader reader = new StringReader(xmlWTF))
{
this.WordTreeFreqNode = (WordTreeFrequencyNode)xs.Deserialize(reader);
}
This is the code. Do you have any idea how do serialize? Are there a better "unity" wayd to deal with it ? I need to retrieve the content of the xml file for my game to run. The Xml file is quite heavy 100mb, it is loaded from a prefab with:
var xmlFile = Resources.Load<TextAsset>("WTFRX$$anonymous$$L");
To sum up:
1- The WTFRX$$anonymous$$L prefab is loaded from asset by Resources.Load =>xmlFile.
2- The xmlFile.text is serialized into WordTreeFrequencyNode.
Your answer
Follow this Question
Related Questions
Application.LoadLevelAsync() causes Unity crash? 2 Answers
How do I stop the GUI from flickering on a new scene? 0 Answers
Got a problem with Async! 0 Answers
Async Scene Creation 1 Answer
Geometry not rendering after Application.LoadLevelAdditive 0 Answers