Hey! So, I'm new to Godot. I made a Memory Card mini-game inside a Platformer Game - it launches when my platformer Character interacts with Area2D.

I would like to make the Memory Card mini-game reset or restart every time I click the "Cancel" button, so when I interact with it again the mini-game will start over. Right now, because I just hide/show the node, it just saves all the parameters and when I interact with Area2D again it just continues instead of reloading the node. The thing is, I don't know what to do to reset or reload the node. I tried queue_free() but it just deletes the node completely and I cannot interact with it again.

Here's a short video of the problem:

I'm still starting out but my understanding is you'd do this:

At the top of your script define a variable that preloads the scene you want to recreate:

var cardGameScene = preload("res://Scenes/CardGame.tscn")

That's a path to the scene in your resources rather than to the created scene in your project.

Then during the game when you need your existing scene to be reset you'd call queue_free(). And then you can recreate a new instance of the card game scene with:

variableForYourNewScene = cardGameScene .instance()

And you then need to make sure you add this new scene in to the game with:

add_child(variableForYourScene)

If you don't call add_child() then you haven't told Godot where in the game's tree you want this new node/scene to exist. Essentially make sure to put it in the same place your old scene was in the tree. For example:

$VBoxContainer/MarginContainer.add_child(variableForYourScene)

Note: I'm not sure if you would do that above line or:

get_node("VBoxContainer/MarginContainer").add_child(variableForYourScene)

I think they're the same but not 100% confident.

2 years later