need help removing a scene from the game

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

I have a game in which there is game menu which asks the player what spaceship he wants, this is child of a node2D which should remove it after the player chooses his spaceship and runs the other game scene but it error and gives
error code: Cannot call method ‘queue_free’ on a null instance
Varia is a script that i just use to store my global variables
main is the node in which the game takes places

func _process(_delta):
if varia.spaceship1:
	get_node("Control").queue_free()
	var game_scene = load("res://main.tscn").instantiate()
	add_child(game_scene)

help me fix this
any and all help is appreciated thanks

:bust_in_silhouette: Reply From: GrandNecro

get_node only looks at the subnode in self. The error saying “null instance” means that the function get_node cannot find any node named “Control”.

Make sure the path to the node is correct. For example, if you have the Control node nested under several nodes, you have to mention that in the path:

main
|
+- spaceships
  |
  +- spaceship1
    +- Control

then you have to get the node by

get_node("./spaceships/spaceship1/Control").queue_free()

thanks very much.

Master0987 | 2023-04-01 11:35