tree_entered() not triggered when instancing a node?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ghostofthewok

Hi all!

I’m pretty new to using Godot and am running into trouble with the tree_entered() signal from Node2D. As a test case, when I try to add a new item when I press the space bar, in my Node2D script I use (in func _process):

if Input.is_action_just_pressed("ui_accept"):
    new_item = load("res://item.tscn").instance()

When I run this, press space, the new node appears as a child to my Node2D in the scene tree. However, if I now want to run a different function when this item enters. So, I connect the _on_Node2D_tree_entered signal and try to print something:

func _on_Node2D_tree_entered():
    print("A new item appeared")

This does not work. I thought instancing a new node triggered the tree_entered signal? Or am I using this wrong and there is a better method?


:bust_in_silhouette: Reply From: ghostofthewok

My bad, I figured out my issue. I was under the impression that the get_tree signal came from the parent tree, not from the node that entered the tree. As a workaround to my problem, I used the tree_changed() signal from the parent and things are now working as desired.