Godot version:
Godot 3.1.1
OS/device including version:
ArchLinux
Issue description:
When I try to reparent a button with
var AnotherParent = get_node("path/to/another/parent")
get_parent().remove_child(self)
AnotherParent.add_child(self)
my signals stop working.
For example, if I reparent the button when it is clicked (button_down signal), then I won't receive button_up signal after releasing the mouse. However I can click again, and receive button_down again.
Steps to reproduce:
button_down and button_up signals to itselfMinimal reproduction project:
signals_when_reparenting.zip
The callbacks still exist if you reparent.
I'm not sure if this is a bug or intended. The signals are probably thrown away when you remove the object.
The problem is the button_up signal doesn't get a chance to execute the callback before the object is removed. Alternatively, you would remove the object after you receive the signal and perform the callbacks.
Well I'm just gonna share a workaround that I used to solve this problem.
Instead of using the signal button_up I used the _input() method.
var clicked = false
func button_down():
clicked = true
# reparent stuff
func _input(event):
if event is InputEventMouseButton:
if clicked and not event.pressed:
clicked = false
# reparent stuff
Currently all UI elements seem to treat removed and invisible controls as losing focus. Do you have use cases where controls are moved in the tree? If it's general enough this behaviour could be changed.
Details: signals have nothing to do with this. It's caused by the viewport resetting the currently focused element on child removal.
The button resets its state as well.
Do you have use cases where controls are moved in the tree? If it's general enough this behaviour could be changed.
Yeah. I was making an inventory system, where all items are in a scroll container, but when you pick an item up, and drag it somewhere, the picked up items would disappear if you dragged them outside of the scrollContainer bounds. So then I decided to move all picked up items to another container, and when they're released somewhere, move them back to the scrollContainer.
I tried the project and I don't actually see any bug. The button_down signal is received correctly. The button_up doesn't arrive, because _it's never emitted_. The button is unpressed, however no via input, but due to being removed from the tree, so it doesn't emit the signal. Case closed.