Sequential loading of scenes?
24 December 2019 01:05
Hello!
I have created a project where sets of scenes can be loaded or saved together, and there are parent/child relationships that need to be set across those scenes.
My problem is that when I reload a set of scenes, apparently sometimes the child gets loaded before the parent and I get an 'object not found' error as a result.
Is there a way I can force scenes to load sequentially so that the parent scene loads before the child scene?
Thanks!
I have created a project where sets of scenes can be loaded or saved together, and there are parent/child relationships that need to be set across those scenes.
My problem is that when I reload a set of scenes, apparently sometimes the child gets loaded before the parent and I get an 'object not found' error as a result.
Is there a way I can force scenes to load sequentially so that the parent scene loads before the child scene?
Thanks!
24 December 2019 07:29
I found something that seems to be working so far. Posting here in case anyone else needs this, or if someone can suggest a better approach:
function load_wait() {
var done_yet = m_data.is_idle()
if(done_yet) {
clearTimeout(t);
***code to run after completion of load goes here***;
} else {
var t = setTimeout(load_wait, 1000);
}
}
24 December 2019 21:27
You don't need to make your own "load_wait" because m_data.load() has a built-in callback for load completion, so you can use that to set up any load order you want:
function load_first() {
var id_of_first = m_data.load("first_file_to_be_loaded", load_second);
}
function load_second() {
var id_of_second = m_data.load("second_file_to_be_loaded", load_third);
}
function load_third() {
var id_of_third = m_data.load("third_file_to_be_loaded");
}
// start load sequence:
load_first();
08 January 2020 22:20