0 votes

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

Godot version 3.2.3
in Engine by (72 points)

1 Answer

0 votes
Best answer

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.

by (2,394 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.