Global Transform not being kept properly on reparenting

Godot Version

4.3

Question

Im working on a card game on godot. I already programmed a deck (where you draw cards from), a hand (where you keep the cards) and rn im working on the “playing the card” feature.

This is code from my hand node:


Here i declare a variable to more easily reference the card that’s being played, then do some internal logic on the card to adjust a pivot node then reparent the card to the playground node. Even though i didn’t put “false” as the second parameter in the reparent method, the global transform is not being fully kept. The rotation of the card is kept, but the position isn’t, the card just snaps to the (0,0) of the new parent (playground). How can i fix this?

One more thing, in the line 119, the game crashes if i put in “global_rotation_degrees” instead of “rotation degrees”. I assume it’s due to the reparenting? Still not sure though.

In line 113 you are changing played.global_position to played.handle.global_position. Check if maybe played.handle.global_position is equal to Vector2.ZERO (with a print() statement for example), that could explain the first part of your problem.

As for the crashing on line 119 - I don’t see a reason why it shouldn’t work with global_rotation_degrees. Is there any error in the console you can show?

unfortunately the issues still happen if i comment the lines 113 and 114, i highly doubt it’s related to that. Also, the “global_rotation_degrees” doesn’t seem to be an issue anymore? lol. lmao even. But yeah it fixed itself somehow, ty

Try to include a couple of print statements before and after reparenting to see what is the global_position before and after reparenting. I have a feeling that snapping to Vector2.ZERO happens somewhere else, not in this piece of code.

Edit: could be that the Tween snaps its position, try to comment it out to see if this helps.

ok this gave me some really weird info


i made it print three time per card played, once before and after reparenting and once on tween callback. The ones before and after reparenting are the same, but the one on tween callback is different, even if the tween literally has no tween actions! I have NO idea what’s making the card’s position snap to (0,0)

The printout from within the Tween shows something different than the first 2 printouts, because the Tween actually starts on the next frame after it is created.
Therefore you must have a piece of code somewhere else that manipulates the played card’s position (or its parent).

At least you know this piece of code here works alright, you just need to dig a little deeper somewhere else to find the rootcause.

i found the culprit! still don’t know how to fix it


the line 81 is the cause of it instantly going to (0,0).
My guess is that as soon as the node get’s reparented, all the tweens associated to it go to their end states immediately. How would i be able to fix this?

(in case it isn’t clear why that line is even there, it makes the card go back to the original position if its the one being hovered over or the one to the left of it, like this)

Can you specify what is exactly going wrong visually? Can you see that on the video you shared somewhere? If so, which part exactly is going wrong?

a bit silly for me to not have shown this at first.


this is it: the first two cards i play simply snap into place while the third one works (i found out it just works normally if the “selection hover” has no time to do it’s thing

ok so i found the actual cause of this problem, and this discussion is getting a bit too long so i’m going to create another one more focused on what i found out and what i think the problem is.

The problem being:
Reparenting with tweens active causes issues with things snapping to their final destinations.

1 Like

SOLUTION!
dont try to kill() the tween when something like this is happening to you, stop() it. the stop function just drops everything immediately, not further changing the node’s position