Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_node() does not accept StringName variables as a valid argument #71319

Open
TisFoolish opened this issue Jan 13, 2023 · 6 comments
Open

get_node() does not accept StringName variables as a valid argument #71319

TisFoolish opened this issue Jan 13, 2023 · 6 comments

Comments

@TisFoolish
Copy link

TisFoolish commented Jan 13, 2023

Godot version

4.0 Beta 11

System information

Win 10, Forward+, 1080ti, 516.94 driver

Issue description

Simply put if you try to get a node by using a StringName as an argument you'll get the error

Parser Error: Invalid argument for "get_node()" function: argument 1 should be "NodePath" but is "StringName".

which is likely an oversight because doing get_name() on a node gives a StringName.

I came across this when I was trying to loop through some nodes, checking names of nodes in an array vs the children of a node, but was able to easily work around it by making the array a string typed array

Steps to reproduce

I uploaded an mrp, but the code is as simple as

var nodeString = StringName("Node")
var test = get_node(nodeString)

Minimal reproduction project

bug.zip

@PrecisionRender
Copy link
Contributor

PrecisionRender commented Jan 15, 2023

Try test = get_node(NodePath(nodeString)) as a workaround.

@TisFoolish
Copy link
Author

Like I said, I just typed the array to String

@thehappycheese
Copy link

To give a practical example, I encountered this issue like this (v4.0.stable.official [92bee43]):

var graph_edit:GraphEdit = $"../Panel/VBoxContainer/GraphEdit"
for connection in graph_edit.get_connection_list():
    var graph_node = graph_edit.get_node(connection.from) # <<< ERROR

The solution is to modify graph_edit.get_node(String(connection.from)) which converts from:StringName to from:String allowing it to be automatically coerced to from:NodePath. I would hope that in future StringName would automatically coerce to NodePath as expected, or else graph_edit.get_connection_list() should return {from:NodePath,...}[]

@goatchurchprime
Copy link

I've just hit this bug with an @rpc call over a dict where some of the values were randomly arriving as StringNames, in particular the one which held the nodename value.

This weird type is only made visible when you print the whole dict and there's this unexpected '&' after the ':'.

@AThousandShips
Copy link
Member

@shafnaz
Copy link

shafnaz commented Dec 20, 2023

Also getting similar error trying to get a node in a scene.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: To Assess
Development

No branches or pull requests

7 participants