This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

Hey!

I'm having a surprisingly hard time trying to do what I see as a simple task. I need to spawn in a node (loot) around when another node (enemy or chest) is destroyed.

The only way I can think to do this is with add.child but that doesn't seem to be working.

I've tried different variations of

onready var coins = get_node("/root/MainScene/Coins")

func on_interact(player):
    self.add_child(coins)

    #player.give_gold(goldToGive)

    queue_free()

to no avail. Any ideas?

in Engine by (22 points)

1 Answer

+2 votes
Best answer

When you use queue_free(), you delete the child nodes of the node you're deleting. Since you made the coins node the child of the node that gets deleted, it gets deleted as well. So you shouldn't make it a child node, just change its position to wherever you want it to be.

by (8,580 points)
selected by

That makes perfect sense. Thanks

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.