How do you instantiate a scene to respawn?

Godot Version

Replace this line with your Godot version

Question

`How do you instance a scene. Like just make things re-spawn? I am reading docs but I’m not sure how to use it correctly. For example, if Y touches X how can I get the Y to respawn? I know I can use queue_free() to eliminate the node.

Also is it possible to instance a child node?

I would really appreciate a breakdown! `

1 Like

You can just create a function of respawn, where it will do its job, like maybe it will return to a specific position, etc. You can call this whenever need.

2 Likes

Here is a very quick video by someone on YouTube breaking it down.

@export var enemy_scene: PackedScene
@onready var game = $ReferenceToYourMainGameScene
# drag and drop the scene you want to
# instantiate in the Inspector into the
# export variable above

var enemy = enemy_scene.instantiate()
# do things to this enemy instance like set position
game.add_child(enemy)

Roughly, the above would do what you want. Use that in conjunction with the video to get a better idea for your purposes.

Of course, this could be stored in a function, that gets called when a signal is emitted, say from a timer that spawns a new enemy every 5 seconds.

Lots of ways to do this and set it all up.

Good luck!

Thank you! Exactly what I needed

1 Like