Hi there, I've got a node (A). In scripting, I instance another scene and add it to A by calling add_child()
. Let's call the child B. The _enter_tree
and _ready
notifications are received on B (I can confirm by printing messages there).
After B is added during a run, the relevant part of the hierarchy looks like this:
- A (KinematicBody2D)
- Animation (AnimatedSprite)
- CollisionShape2D
- B (Node2D)
Later, from I want to access a sibling of this node (an AnimatedSprite named Animation) from within B, so I do this:
var parent = get_parent() # Works -> returns "A"
# The following works. It prints A's three children, including "Animation"
for c in parent.get_children():
print(c.name)
# None of these works...
var anim = parent.get_child(0) # returns Null
anim = parent.get_node("Animation") # also returns Null
anim = get_node("../Animation") # also returns Null
In my Remote (debugging) view, I can see all the nodes are in the tree, as described above.
Any suggestions on how I should proceed to debug/investigate further?
Thanks,
Glen.
UPDATE: It turns out it actually is working, and appears to be a debugger issue... it does return a valid AnimatedSprite object on which I can access properties and methods. However, in the debugger, the anim
variable shows as Null
. This makes for confusion when you're a relatively new user, since you step through the code and it appears to be failing... When accessing other children in the same way (e.g. parent.get_node("CollisionShape2D")
it does shows a "proper" returned object in the debugger).