#Reparenting a node, sometimes global_transform is lost
1 messages · Page 1 of 1 (latest)
So my issue was I needed to use call_deferred for some reason
I found this while trying another reparent method someone posted:
https://www.reddit.com/r/godot/comments/mgycy8/preserve_global_position_when_reparenting_child/
I decided to keep their method so I can also reset the rotation to 0 as I only want to preserve the position
func change_parent(child, new_parent):
call_deferred("_reparent", new_parent, child, child.get_global_transform())
func _reparent(new_parent, node, old_transform):
node.get_parent().remove_child(node)
new_parent.add_child(node)
node.transform = new_parent.get_global_transform().inverse() * old_transform
node.rotation = 0
😄
It might have been because if the physics ticks lined up badly with the processing ticks or something it would get messed up
Also that call_deferred is deprecated. You can now call Callables deferred-ly directly:```php
_reparent.call_deferred(new_parent, child, child.get_global_transform())
If you have multiple lines you want all to be called deferred-ly, you can wrap them in a lambda and call *that* deferred:```php
(func():
_reparent(new_parent, child, child.get_global_transform())
print("right after _reparent!")
).call_deferred()