How to make a node spawn another node independent from each other

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By WelpHelp

I want to use it so before the enemy that dies on a timer with queue_free() spawns an item(area2D so when it’s touched the player gets a power up) but when it queue_frees itself it doesn’t also destroy the node it just created.

:bust_in_silhouette: Reply From: Kyle Guarco

Make it a child of the parent instead.

self.get_parent().add_child(child : Node)
:bust_in_silhouette: Reply From: Magso

You have to add the power up scene as a child of the scene node like this

get_owner().add_child(powerUp)
queue_free()

Thank you, now I’ll figure out how to set it to enemy’s last position and I’m done!

WelpHelp | 2019-04-20 23:43

If the script is on the enemy you can do

func _ready():
    powerUp.set_translation(translation)

Magso | 2019-04-21 19:17