Queue_free() resets position of my tweened Object

Ah, thank you for that. Although I am not sure why hiding it wouldn’t work then? Does a re-layout reset the visible property as well?

Hiding has the same effect as removing for our purposes here, the immediate container parent (HBox) does a re-layout, changes size on account of the now invisible child, which triggers a re-layout of it’s parent (the VBox).

This all got me thinking though: what if the immediate parent doesn’t change size? So I just tested that out, and it actually works.

Note that this is hacky and I totally do not recommend it, from what I’ve seen of project I would recommend doing away with the VBox (and Margin) and positioning things with anchors.

My test setup:

extends Control

func _on_button_pressed() -> void:
	var pos: Vector2 = $VBoxContainer/HBoxContainer2/TextureRect5.position
	pos.y += 250
	var tween = create_tween()
	tween.tween_property($VBoxContainer/HBoxContainer2/TextureRect5,  "position", pos, 1.5)
	tween.finished.connect(foo)
	
func foo() -> void:
	# Either works...
	#$VBoxContainer/HBoxContainer/TextureRect2.visible = !$VBoxContainer/HBoxContainer/TextureRect2.visible
	$VBoxContainer/HBoxContainer/TextureRect2.queue_free()

Which will (by default) exhibit the undesirable behaviour.
I then set the HBoxContainer’s custom minimum size to it current size:

and that prevents the parent container update.

create_tween is tied to the object that calls it, if the object is destroyed so is the tween. maybe try _bottom.create_tween

Okay so, just to ensure I understand, the best move is to redo the structure to use anchored nodes instead of the containers then for the positioning?

Getting rid of the ‘top level’ containers would be my recommendation, yes (the margin and vbox). The Top, Enemies and Bottom containers can stay, you would just be positioning/sizing them with anchors instead of letting the vbox handle that.

This is of course based on what I can see now, there’s no real need for the VBox and you can achieve what you have now with anchors easily, if you are planning to add more things… maybe that changes :person_shrugging:

1 Like

Thank you so much for the help! Removing the top containers and repositioning everything fixed the tween problems.

1 Like

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