Topic was automatically imported from the old Question2Answer platform.
Asked By
SCV-ready
Hello. i have been trying to set up a level loading system that does not switch scenes.
in each level there is light2D’s and a canvas modulate along other things.
when i instantiate a level and add it to main as a child it loads, but for some reason the CanvasModulate is not doing anything.
here is my loader code:
func load_level(file : String):
var new_level = load(file)
var level = new_level.instance()
level.name = "level"
if $"/root/Main/".has_node("level"):
var old_level = $"/root/Main/level"
for child in old_level.get_children():
child.queue_free()
old_level.replace_by(level)
old_level.queue_free()
$"/root/Main".add_child(level)
this code runs in a singleton.
any idea how to fix the issue/ how to implement non whole scenetree levels?
For future reference if someone gets this obscure bug:
managed to work by using remove node on the old level and queue_freeing it afterwards instead of replace by.
I just wanted to thank you for sharing this. I have been having a near identical issue. Your solution did not immediately work for me. To fix things I also had to add a one game-loop delay between the old scene being removed and the new scene being created. I assume something about two CanvasModulate2d nodes operating on the same layer causes problems? I was able to solve my version of the issue by deferring the creation of the new scene, whether by using call_deferred() or the briefest of timers.
Again, just adding to this in case someone else comes along. Thanks for sharing your solution and starting me in the right direction!