godot: Using NodePath with certain default values shows an error in editor
Godot version
3.4 RC2
System information
Windows 11 x64
Issue description
If you try to use an exported NodePath
variable with a default value of ""
, NodePath("")
or NodePath()
the editor will throw an error when trying to use a node that uses that variable:
ERROR: (Node not found: "" (relative to "/root/EditorNode/@@592/@@593/@@601/@@603/@@607/@@611/@@612/@@613/@@629/@@630/@@639/@@640/@@6275/@@6109/@@6110/@@6111/@@6112/@@6113/Control/Panel").)
at: (scene/main/node.cpp:1325)
Is something very similar to when you try to use a node in a tool
script.
This error doesn’t breaks the editor or the game. but this was working on 3.3
Steps to reproduce
- Create a node and attach this script
export(NodePath) var ReferenceNode_path:NodePath = NodePath("") # Fails with "" || NodePath() || NodePath("")
onready var reference_node:Node = get_node(ReferenceNode_path) as Node
func custom_function() -> void:
reference_node # <- Try using any of its properties after running the game
Minimal reproduction project
Thanks to eons on discord helping me to replicate this issue: project.zip
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (16 by maintainers)
@AnidemDex I think what you’ve highlighted is an existing problem, but a problem nonetheless. If the problem you describe is the same as I noticed and it’s related to the auto-completion, we can adjust the title/descripting in the OP and keep it open. Unless this is a duplicate.
However, @Listwon’s report seems to be about something new. That probably deserves a new issue report so that we can properly track it and hopefully fix for the next 3.4 RC.
@AnidemDex Errors with auto-complete are caused by user code. It fails trying to get the reference to the object, because it tries to execute
get_node()
to get the value from a node path which is in this case invalid. If you useget_node_or_null()
instead, there are no more errors. I’m not sure if anything can be changed in the engine to address that, because it fails on executing the code that the user wrote.The results are cached after the first run, so it shouldn’t contribute to the slow down when it’s the same base types. See https://github.com/godotengine/godot/pull/51211
@Listwon’s issue might be related to daa0977c68faa7b1be3dc3838c07dcdf23cd790e / #52126.
@pycbouh I’m trying to find it right now and prepare the MRP. What I found so far is that one of the scripts loaded by
EditorResourcePicker::_get_allowed_types()
(checked with VS debugger) on project loading tries to preload scenes in const Dictionary like this:and I get Node not found errors. If I try to open one of those scenes, I’m flooded with cascade of similar errors