My project overview:
I made a simple scene, and the subscene named Coin, while I create a script in the root node: Game, I cannot use
get_tree() in the
var tree = get_tree()
print(tree) # got nil here!
So I change to use signal in Game node:
tree_entered() , now the
get_tree() is not nil, however I still cannot get the nodes in specified group (
coin group here ):
var coins = get_tree().get_nodes_in_group('coin')
print('coin size: ', len(coins)) # coin size: 0
So how to correctly use
get_tree().get_nodes_in_group('coin')? I found that if I add this code
yield(get_tree(), 'idle_frame') before retrieving the nodes in groud, but that's not what I WANT, so how to solve this problem? Help me, and thanks very much!