Hello there,
I am quite new to Godot and am having a blast trying out new things with it, but currently I am stuck with a problem that I can't seem to figure out, although it seems pretty simple. Assume a project structured like this:
res://
--levels (folder)
----level1.tscn
----level2.tscn
--game (Node2D)
----level (Node2D)
----player (KinematicBody2D)
This aren't all the parts of my tree but the others don't matter here. The idea is to keep the levels in a seperate folder to keep everything ordered and tidy, and I want to get the nodes with a script attached to level in order to add and remove them as child to it, depending on what level the game is supposed to show. After researching for 3 hours and trying everything out I find, nothing seems to work as I saw it. Since I need the node in order to it beeing added as a child, the get_node() method is required, but I cant find ANY valid possibility for the path argument to find the levels in the folder. The eror message mostly is the following:
E 0:00:00.338 get_node: (Node not found: "/../levels/level1" (absolute path attempted from "/root/game/level").)
<C++ Error> Method failed. Returning: nullptr
<C++ Source> scene/main/node.cpp:1462 @ get_node()
<Stack Trace> level.gd:13 @ _ready()
I think it has something to do with the path being kinda "fixed" to /root/game/level, but I have no idea to fix it. I also tried lots of variations with get_tree(), get_parent(), the "../.." method but nothing worked out for me.
Does anyone have an idea how to corretly implement this and furthermore, is this even a good project structure or should i manage this in a different way?