get_tree().get_nodes_in_group() returns null instance

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

I have no clue why this keeps happening as I’m using the exact function I’ve used in other projects.

func _on_Button_pressed(button):
 button.disabled = true

func update_row_state(button):
	var buttons = get_tree().get_nodes_in_group(button.type)
	for button in buttons:
		if button != button and button.pressed:
			button.pressed = false

I know for a fact the buttons are in the group, and I know it’s looking for the right group, it just keeps giving me the error “Attempt to call function ‘get_nodes_in_group’ in base ‘null instance’ on a null instance”

:bust_in_silhouette: Reply From: hilfazer

It’s get_tree() that returns a null instance. It means your node is not in a SceneTree when get_nodes_in_group() gets called.

You can check if a node is in a SceneTree with is_inside_tree().

Yep this is correct. I connected the _on_Button_pressed signal within the button node itself by instancing the main scene which led to a bunch of funky logic.

DigitalDrako | 2020-08-17 07:13