Hi,
I'm trying to build a module in my utility framework for Godot that adds a scene in parts so when you "switch scenes" with my function the function will load the scene in a thread
then disassemble the scene and then reassemble it in parts (the order is decided by groups)
example on how end result code should look like (from user perspective):
everything in camera should load first then everything in terrain and then everything else
var groups = ["camera", "terrain"]
libSubManager.load_scene_with_interactive("res://scene.tscn",groups ,"task_tag")

here's the code that i currently have (it works sometimes and sometimes it doesn't
also I can't figure out how to get all parents above node so if a node is a child but has a group the code will try to load it even if its parent is not loaded yet , there's also a bunch more bugs I haven't thought of or mentioned if you can help resolve even one of them I'd be really helpful & thanks in advanced for any help,
also I'm aware of ImmersiveRPG's plugin that does this but I can't figure out anything from his code / I have a management system for all threads used in game and for me to integrate his plugin into my framework will take ungodly amounts of energy & time
code:

resource is the scene instance and groups is an array with all the groups entered ("camera" , "terrain")

    ChromiumOS-Guy
    Some questions, some tips:
    1) How is question in title related to context?
    2) Why do you remove and add back children, if they are in node tree? They are already loaded. How is it going to speed up your app?
    3) Naming conventions - apply snake case to childofchilod variable name. Why resource is lowercase but GROUPS is uppercase.
    4) Nested loops - opportunity to split it into smaller functions.
    5) What if there is childofchildofchildofchild node? Node tree is tree. You can make small function to traverse it. Your code will be small and easy to fix.
    6) Lines of code are glued together - use empty lines. Everything is in one function - apply single responsibility principle.
    7) Shorten your line size (see 2 vertical lines in editor at character 80 and 100), for example use additional variables.
    8) Post code instead of image - higher chance someone is willing to test it.

      AspireMint
      I'll answer:

      1. main thread blocks when you add a scene (even if its multi threaded)
      2. when you remove them then switch scenes and then add them back it sidesteps the main thread blocking by "giving" it small pieces of the scene,
        think of it as burping when you drink to much soda at once so you drink slowly
      3. not my finest work its just that at this point I'm just trying to make it work then make it pretty to look at (that's how all my prototypes look)
      4. again same as 3 also I find it easier to read when It's in one place I usually break it off when it gets over 70-80 lines of code (again not my finest work)
      5. there won't be childofchildofchild I'm getting all the children of all the children so childofchild doesn't mean "Child Of Child" it actually means all nodes below child
      6. again same as 3 not my finest work I usually keep a nice spacing between chunks of code (rewriting this code close to 15 times makes you just not care anymore)
      7. again not my greatest work nor will it be
      8. first thing i tired it doesn't post is correctly idk the term but it removes all the "height" of the lines and makes them the same so copy pasting it won't do much good also it removes its color which I find useful

      edit:
      I'll supply you with a file if you want