nodes stay in the same place after moved to a parent in different position

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By 21sully
func swap_slots(i,j):

var slot1 = heroes[i].get_parent()
var slot2 = heroes[j].get_parent()

slot1.remove_child(heroes[i])
slot2.remove_child(heroes[j])

slot1.add_child(heroes[j])
slot2.add_child(heroes[i])

I’m making a turn-based game similar to darkest dungeon, where the heroes can change the slot they’re in during battle.

the slot transition works, they do go to different parents (slots), but in-game the heroes just stay in the same place. I want them to swap places in-game, not just in the node tree. any help would be much appreciated.

enter image description here

:bust_in_silhouette: Reply From: Inces

You need to reposition them manually.
Normally child node is teleported to parent on ready. But ready isn’t called second time after removing and adding again.

heroes[i].global_position = slot2.global_position

and so on

You can manually just make a call to _ready() or use _request_ready() for Node to call _ready() again when the node is added to the scene tree.

zenbobilly | 2022-09-13 04:20