I am trying to make a class which inherits from another class. The below example works except that I can not access anything in the node tree from the inherited class. Please note that subClass is an inner class but also does not seem to work with a normal class (gd script file) be it inherited or not. I can access functions and variables in the class which I inherited from but if I try to call something like "print (get_path())" it just prints nothing and throws an error:
0:00:02:0489 - Condition ' !is_inside_tree() ' is true. returned: NodePath()
C Error: Condition ' !is_inside_tree() ' is true. returned: NodePath()
C Source: scene\main\node.cpp:1780
C Function: Node::get_path
Here is the below code and project file in a downloadable zip.
mainClassScript.gd attached to the root node, a Spatial Node called main:
var testVar = "this is a test var"
printPath() # prints: "/root/main"
containsObject = $sub.subClass.new()
testVar = "test var changed!"
subClassScript.gd attached to a Spatial Node called sub which is under "main" in the node tree:
if event.is_action_pressed('ui_accept'): # press SPACEBAR
print(testVar) # properly prints out: "this is a test var"
testFunc() # modifies testVar to "test var changed!"
print(testVar) # properly prints out: "test var changed!"
printPath() # prints nothing and produces error: Condition ' !is_inside_tree() ' is true. returned: NodePath()
Any help you can offer would be greatly appreciated! Thank you!