How to delete a node in another scene?

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

Basically:
I have a menu with buttons that lead to different levels, and each button, except the first, is inactive until the player completes the level before it. I’ve made each node inactive by placing a node with a color rect and sprite on top of it.

The game cycle also goes like this:
Person selects level from menu
Person plays level
When level is complete, they are taken to a success screen
Person presses button to take them back to menu

What I want to do is just to delete the node, preferably from the script that checks if the level is complete (attached to the world node). From what I can tell, though, get_node() only works for nodes inside the same scene.

So calling

get_node("/root/LevelSelect/Control/NewYork/inactiveny").queue_free()

in the script attached to the world node inside Level1.tscn doesn’t delete the node inactiveny inside SelectLevel.tscn. I’ve tried other variations of the path, but they don’t work either.

I don’t really have a stellar understanding of how this game engine works, but I feel like there might be a really simple fix that I’m missing. Also, each inactive is currently saved as an instance of a scene, if that complicates matters.

:bust_in_silhouette: Reply From: EmanuelOzorio

I think that You can’t delete a node of a scene that is not loaded yet. The nodes of this scene only is loaded when the scene is loaded.

You can do this:

  • Create a script that contais all of “status” that you can set up. Like a save game.
  • Put this script in autoload. This script will works like a Global script.
  • In the scene that you want make the changes, consult the info on global script and then show or hide the nodes.

node.show() and node.hide() is definately the route to go and will save you many sleepless nights

Wakatta | 2020-11-19 05:41