Variable in string not working

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

onready var root_nav = str(get_tree().get_current_scene().get_name())

onready var nav_2d : Navigation2D = "root/" + root_nav + "/Navigation"

I am using this to get the path of a Navagation2D node for path finding and I continue to receive the error

Trying to assign value of type ‘String’ to a variable of type ‘Navigation2D’.

Quite frankly I am very new to Godot and do not know much about these errors or what they mean

:bust_in_silhouette: Reply From: Ertain

In the line

onready var nav_2d : Navigation2D = "root/" + root_nav + "/Navigation"

The thing being assigned (the "root/" + root_nav + "/Navigation" part) is a string. The variable’s type, however, is Navigation2D. That’s where the error is coming from.

If you are wondering, the path to a node is not the same thing as the path from a Navigation2D node. A node’s path is where it’s located in the scene tree, while the path of a Navigation2D is one that was laid by the user.