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: