Queue_free() resets position of my tweened Object

Hello! I am trying to animate an HBoxContainer in a 2D Scene. I Tween it to move its position to off screen to let a second DialogueBox slide on screen. For some reason, when I call queue_free() in a separate Function for the removal of an Enemy, it resets the position of my HBoxContainer that has already moved offscreen. I can fix this behaviour by calling queue_free() after all tweens are finished, however, I would prefer to remove the enemy during Combat rather than once everything is done. Is there some form of workaround or misuse of Tween/Queue_Free()? (Relevant Code in snippets below)

Called before running through combat event queue:

_bottom_start_y = _bottom.position.y
var tween = create_tween().set_parallel(true)
tween.tween_property(_bottom, “position”, Vector2(_bottom.position.x, _bottom_exit_y), TWEEN_DURATION)
await tween.finished

Called during combat when an enemy is defeated:

if hp == 0:
_anim_player.play(“Exit”)
await _anim_player.animation_finished
_remove_enemy()

func _remove_enemy() → void:
queue_free()

_bottom_start_y = _bottom.position.y

Is this code part of the enemy? That is, the hbox being moved, is it part of the enemy node or something else? If something else, how are these things connected?

Its being set in a battle manager. The bottom moves then it starts running through an event queue where the latter two functions fire off

So the hbox is part of the enemy node? The one being deleted?

No, apologies, I should have made that clear.

The Enemy node is a button separate from the HBox Im attempting to move

The HBox is a separate Node containing some buttons that have no relation to the Enemy nodes

Nothing to add to the problem conversation.

Just seeing the Baba Yaga sprite made me smile :slight_smile:

2 Likes

Oh.. so when the baba yaga sprite, which is the enemy, is deleted, the hbox right below it is moved up, yes? That makes sense, since the parent container is compensating for the missing space. Instead of moving the hbox container, maybe you can hide it instead? or move it further down so when it is moved up, it’s still off screen…

1 Like

No. Before the attacks happen, the Hbox below moves down off screen using a Tween.

An enemy is hit, theres an animation, then the enemy is deleted using queue_free(). When the enemy calls the queue_free() for some reason, even though the box is offscreen still and nothing is moving it, its moved back to its original position.

I want to know how to stop the box from returning to its original position everytime queue_free is called

The enemy is the baba yaga, yes? So what you have outlined in red is what gets queue_free() called, right? That space becomes empty? Or do I still mis-understand?

1 Like

So this is the opened HBox:

Yes, the individual btn_Enemy calls the queue_free and is removed

Do you think you can post a video of what happens?

Unfortunately, because I am a new user I cannot upload a video

maybe this will work? https://bruh-clips.com/

What I am failing to understand is, if your enemies line is 5 nodes (5 baba yagas) and one of them is removed, what exactly gets moved up and where to? The hbox in your screenshot is wider than a single baba yaga.. does it somehow squeeze in? Maybe just a screenshot of what it looks like after it has moved back?

Here is the clip:

And the box animating isn’t my problem. My problem is:

  1. The box starts in a position
  2. The box uses a Tween to go offscreen
  3. The battle begins to run
  4. An enemy is defeated
  5. Queue_free() is called
  6. The box moves back to its original position (which it should not do)

And to be clear the box in question is the bottom box. The one that says Fight/Run/Parry/Item NOT the Enemy box itself. That one doesn’t matter

Ok, I see now. Something must be connecting the hbox and the enemies.. what makes the fight box appear in the first place, is it when an enemy is selected? When one enemy dies, is a different one by chance selected? Perhaps you can post more code… sorry, I am out of ideas otherwise…

The fight box is on by default on run. Its moved by a Tween. When an enemy is selected it locks in the selection then goes through the combat text.

At this point, I should probably just do the removal at the end of everything, or find some alternative to queue_free or remove_child

Maybe you can just .hide() it?

Nope. Same problem

I can’t offer you a solution, but I can explain what is happening.

Your Bottom HBox has a container parent. That parent will determine where it is positioned.

You are tweening it, which works because the container parent doesn’t know anything is changing and doesn’t needlessly do relayouts.

You then remove something from one of the parent’s other children, which triggers a re-layout, and your Bottom HBox goes back where it belongs.

I don’t know how/if you are meant to tween things in a container sorry, seems like it would be a bit of a nightmare; certainly for position and size props, they are just going to get reset by the parent container… sooner or later.

1 Like

Thank you! That explains which one is the problem child. Will have to figure out how to rejigger the whole thing to stop doing that