Godot: Node picker for the export NodePath variable doesn't give a correct Node path when is set in a custom Resource

Created on 28 Mar 2020  路  8Comments  路  Source: godotengine/godot

Godot version:
3.2.1

OS/device including version:
Window 7

Issue description:
if you set an export NodePath in a custom resource then pass that resource to another Node and calling get_node() on it will return null
when setting the NodePath in the Resource it gives Node2/Node3/HasNeededVar which gives the error above
and when set in the referencing Node it gives ../Node2/Node3/HasNeededVar which works fine

Steps to reproduce:
so we have a node somewhere with this script on it

extends Node  
var n_var = 10

with a nod hierarchy like so "/root/Node/Node2/Node3/HasNeededVar" and we have a custom resource

extends Resource 
class_name resource_getter  

export (NodePath) var getter 
export (String) var var_name

create and instance of this resource and set the NodePath, and the String for the parameter we want to access manually and in another Node in the same scene add this code

extends Node  
export (Resource) var getter_resource   
func _ready():     
    var getter = getter_resource.getter     
    var var_name = getter_resource.var_name          
    var got = get_node(getter).get(var_name)     
    print (got)

drag the custom resource to the getter_resource var in the inspector and run and get 'can't call get() on base null'
Minimal reproduction project:

NodePath Resource.zip

archived gdscript

All 8 comments

I tried the sample project, but it works without any issue for me.

@Ev1lbl0w sorry I uploaded the version where the NodePath is a String, I fixed it
sorry...

Thanks. I've retried, and yes, the problem is happening if I don't make any changes.

However, when I click on the NodePath field to fix it, it changes the original Node2/Node3/HasNeededVar to the correct ../Node2/Node3/HasNeededVar (fixing the issue), and I can't make it go back to the original value again.

How were you able to set the NodePath to that value?

so the Node picker for the export NodePath variable is the problem when setting it in the Resource it gives Node2/Node3/HasNeededVar
and when set in the referencing Node it gives../Node2/Node3/HasNeededVar

In my actual project when setting the NodePath on a resource it just gives me the node's name no parent no nothing

so this seems like an Editor problem not a GDScript problem @Calinou if you can update this please

so the Node picker for the export NodePath variable is the problem when setting it in the Resource it gives Node2/Node3/HasNeededVar
and when set in the referencing Node it gives../Node2/Node3/HasNeededVar

Ah, so that's how it's happening :smile:

Honestly, I don't know if this is a bug. When you're editing the resource from the node's context, Godot is able to infer the NodePath knowing where it comes from (in this case, Getter).

But when you're editing this resource directly without a scene tree, Godot has no idea where the path will begin, so it assumes the root.

@Ev1lbl0w make sense, then the type NodePath shouldn't be available under Resource, or this solution is too drastic ?

@Ev1lbl0w make sense, then the type NodePath shouldn't be available under Resource, or this solution is too drastic ?

No, your solution works well. The only thing you'll have to do is edit the resource's NodePath directly from the Node, and not on the Resource itself.

You could write a fail-safe code in your game to detect whether the path is absolute or relative too.

I will close this since this seems to be not a bug but a workflow issue on my part

Was this page helpful?
0 / 5 - 0 ratings