Add to Group Reverting

Godot Version

4.3.Stable

Question

Hi,

The node I am adding to a group appears to be removed after adding it. Anyone able to see what I’ve missed?

Printing the group members in _on_construction_timer_timeout() works, but “No builders” is printed from game_controller.gd’s _process(), the arrays are empty here. Nodes aren’t removed from this group anywhere else.

This does work if a building is added to construction_pending array one at a time, i.e. when construction_pending is empty so the basic logic seems good to a point. But adding a node to the construction_pending array while the group is empty seems to result in the node being removed from the group.

  • Building.gd
func _on_construction_timer_timeout() -> void:
	builder.add_to_group("available_builders")
	print(str(get_tree().get_nodes_in_group("available_builders")))
  • game_controller.gd
func _process(_delta: float) -> void:
	if not construction_pending.is_empty():
		var builders = get_tree().get_nodes_in_group("available_builders")

		if not builders.is_empty():
			print("Builders available")
			...
		else:
			print("No builders")
			print(str(builders))
			print(str(get_tree().get_nodes_in_group("available_builders")))

Console output:

is your group global? if not when _on_construction_timer_timeout() runs then that group will be local to that scene

It is a global group. I forgot to mention that.

image

After going through my scripts with a fine tooth comb I found a function duplicating the removal from the group logic. It was part of an old experiment, which when removed resolves the issue.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.