|
|
|
 |
Reply From: |
ICatRegister |
Use ResourceLoader interactive mode and move it outside bg thread
thread.start(self,"prep_scene", ResourceLoader.load_interactive(path))
Change your “prep_scene” method like this :
func prep_scene(interactive_ldr):
while (true):
var err = interactive_ldr.poll();
if(err == ERR_FILE_EOF):
call_deferred("_on_load_level_done");
return interactive_ldr.get_resource();
Add another func, wait thread and use loaded resource:
func _on_load_level_done():
var level_res = thread.wait_to_finish()
var scene = level_res.instance();
add_child(scene);
it returned an error on the resourceloader line :
parser error : identifier not found : path
0:00:01:0639 - Condition ' _debug_parse_err_line >= 0 ' is true. returned: 0
what do you mean “move it outside background thread” ? how do I do that ? Is it why it’s still not working ?
Thanks again !! --_–
nonomiyo | 2018-07-15 18:50
“path” must be a valid path to resource, in your case this is “res://scenes/waitingroom.tscn”
i mean ResourceLoader should be run from main thread. it’s already done in this line
thread.start(self,"prep_scene", ResourceLoader.load_interactive("res://scenes/waitingroom.tscn"))
ICatRegister | 2018-07-16 10:13
hmmm I tried that but it’s not working at all :
I still have the godot logo for 13 sec on launch, but when I click on “play”, it goes to the waitingroom scene and stays there.
just to be sure I did things right, this is what I have now in the autoload singleton’s script :
extends Node
onready var thread = Thread.new()
onready var current_scene = get_node("/root/titlescreen")
func goto_scene(new_scene,loading):
current_scene.queue_free()
current_scene = new_scene
print("goto_scene OK")
print("current scene =" + current_scene)
print("new scene =" + new_scene)
get_tree().get_root().call_deferred("add_child",current_scene)
if(loading):
thread.start(self,"prep_scene", ResourceLoader.load_interactive("res://scenes/waitingroom.tscn"))
func prep_scene(interactive_ldr):
print("print prepscene")
while (true):
var err = interactive_ldr.poll();
if(err == ERR_FILE_EOF):
call_deferred("_on_load_level_done");
return interactive_ldr.get_resource();
func _on_load_level_done():
var level_res = thread.wait_to_finish()
var scene = level_res.instance();
add_child(scene);
Thanks for sticking with me on this problem ICatRegister, I really appreciate it !!
It feels like it’s something that should be super easy to code but it’s a damn puddle of mud…
nonomiyo | 2018-07-16 10:58
the code seems to be correct, except mess with order of scenes loading.
as i understand scene “ingame.tscn” is the largest, so you need:
- Show title scene
- Preload or load waitingroom.tscn, free title scene and show waitingroom.tscn
goto_scene(load(“res://scenes/waitingroom.tscn”).instance(), true);
- Load your largest scene in thread
thread.start(self, "prep_scene", ResourceLoader.load_interactive("res://scenes/ingame.tscn"))
- Free waitingroom .tscn and show ingame.tscn
func _on_load_level_done():
var level_res = thread.wait_to_finish()
var scene = level_res.instance();
goto_scene(scene, false);
ICatRegister | 2018-07-16 16:37
OK, it is working now !! 
argh, I was starting to lose hope here : it was working but it was taking about 40 sec (!) to run the ingame scene with this thread method
BUT I was using godot v3.0.2. Just updated to 3.0.5 and now it’s working perfectly fine
(weight out of my chest !)
Thank you so much mate, you’re a boss ! 
nonomiyo | 2018-07-17 10:01
one laaaast question though :
get_tree().reload_current_scene()
this command, which is set in the ingame scene’s script, is not working anymore.
do you know what I could replace it with ?
nonomiyo | 2018-07-17 13:16