Topic was automatically imported from the old Question2Answer platform.
Asked By
Robster
Old Version
Published before Godot 3 was released.
Hi all,
I am making an arkanoid clone for learning. I have this line which appears to be called when I press escape, to leave the current scene and load the main menu:
if get_tree().get_nodes_in_group("balls").size() <= 1:
for ball in get_tree().get_nodes_in_group("balls"):
if ball:
#do stuff here
I get the following error: Attempt to call function 'get_nodes_in_group' in base 'null instance' on a null instance.
There are definitely ball/s on screen when I press escape. The code above is within a function called:
func _on_Timer_timeout():
So I can’t see even why the timer would be triggered and time out.
I’m a little confused. Can anyone see or think of anything that I’m missing?
It seems like your node is not inside the scene tree, therefore get_tree() returns null. You might want to check this before running your code with is_inside_tree().
Thank you! That’s a great little function. I can already see other ways I can use this. Much appreciated. Problem now solved.
Robster | 2017-07-24 23:12
How could you fix that problem, please? I’m acrossing a similar issue
EmmanFK9503 | 2019-12-06 15:15
Hi there, I used is_inside_tree() as per /u/timoschwarzer suggested. I hope that helps
Robster | 2019-12-07 00:47
@Robster I think what he meant is, how did you actually fix the error? I am running into the same issue now.
tmit30 | 2020-08-11 20:47
Indeed. I guess looking back (this was a long time ago) I PROBABLY did something like:
i
f get_tree().get_nodes_in_group("balls").is_inside_tree():
if get_tree().get_nodes_in_group("balls").size() <= 1:
for ball in get_tree().get_nodes_in_group("balls"):
if ball:
#do stuff here
This is a guess and the code is backed up in cold storage now but I suspect I was using the function is_inside_tree() to check first if the node was actually inside the scene tree.