Hi all
I have a smoke trail GPU2DParticles effect attached to a rocket. If the rocket explodes and is removed from the tree, I'd like the effect to be reparented to another node (root in the example), so that the trail remains and does not immediately disappear with the rocket.
I used to do this explicitly (reparent on collision -> explosion), but I am wondering if this could be done on e.g. tree_exiting or another signal or method call on a script on the effect itself.
extends GPUParticles2D
func _ready() -> void:
connect("tree_exiting", trigger_reparent)
func trigger_reparent() -> void:
# Silently does not work.
# call_deferred("reparent")
# Error: trigger_reparent: Parent node is busy setting up children.
reparent()
func reparent() -> void:
var gp = global_position
self.get_parent().remove_child(self)
self.get_tree().root.add_child(self)
self.global_position = gp
If I immediately try to reparent in tree_exiting, I get the cryptic "Parent node is busy setting up children." (I assume the parent node state is just not ok for removing children between tree_exiting
and tree_exited
)
What is the best way to reparent e.g. effects on parent death? Thanks!