Using Control.reparent to an HBoxContainer does not rearrange the Control into the container

Godot Version

godot 4.3

Question

Hello. I’m following the “Slay the Spire clone” tutorial here (using Godot 4.3):

And got problem with the reparent() method not working in expected way.

Basically, an HBoxContainer is attached to a script hand.gd, which has a function _on_card_ui_reparent_requested. CardUI is a subclass the Control:

class_name Hand
extends HBoxContainer

func _ready() -> void:
    for child in get_children():
        var card_ui := child as CardUI
        card_ui.reparent_requested.connect(_on_card_ui_reparent_requested)

func _on_card_ui_reparent_requested(child: CardUI) -> void:
    print("hand got request reparent", child, self)
    child.reparent(self)
  1. The signal card_ui.reparent_requested is emitted when a game card object instance (card_ui) is dropped in non-target zone.
  2. The Hand._on_card_ui_reparent_requested should be called with the card object to be snapped back into the Hand container by calling child.reparent(self).
  3. I’ve checked _on_card_ui_reparent_requested is called with what seems to be the correct child and self. But the child was never reparent to the self (Hand).

How best to start debugging this?

Control.reparent() (or Node.reparent to be precise) on actually reparent if the parent was changed to another node.

In my case, a programming error on my part (i.e. I forgot to add certain node to scene group) stopped by dragging logic from reparent the CardUI to another node before reparent here. So when a signal triggers Hand._on_card_ui_reparent_requested(), the CardUI involved was always belong to the Hand, so there is no actual reparent needed.