-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Exported NodePath has inconsistent empty values #21556
Comments
As far as I know that's by design, any identifier with no value assigned is So for GDScript, On the other hand, once you've assigned data to the identifier, it has a type, and clearing it will give you an empty object of that type (unless you clear it by assigning to Consider this example which is valid GDScript: export(NodePath) var node_path
export(Dictionary) var dict
export(Vector3) var vec3
func _ready():
print(node_path)
print(dict)
print(vec3)
node_path = 42
dict = "Hello world"
vec3 = ["It's a duck"]
print(node_path)
print(dict)
print(vec3) Prints:
|
Now with type hints: export(NodePath) var node_path: NodePath
export(Dictionary) var dict: Dictionary
export(Vector3) var vec3: Vector3
func _ready():
print(node_path)
print(dict)
print(vec3) Prints:
So it works fine, apart from the fact that empty NodePaths don't seem to have a proper |
I see. I still think that it should be discussed because it can represent a problem. if nodepath == null:
my_thing = get_parent()
else:
my_thing = get_node(nodepath) This worked until I opened a scene, assigned the nodepath and cleared it. What happened then is that the object was trying to reference itself as the my_thing and my game crashed. Tracking down this bug wasn't very hard but i think this should be addressed in a more elegant way. |
IMO in your use case you should either use type hints, or initialize your export vars to make sure that they're not null, so: export(NodePath) var nodepath = NodePath()
# or
export(NodePath) var nodepath: NodePath
...
if nodepath == NodePath():
my_thing = get_parent()
else:
my_thing = get_node(nodepath) Or of course use belt and braces with |
I don't think we can change the fact that Within a script, export(NodePath) var node_path
export(Dictionary) var dict
export(Vector3) var vec3 is exactly the same as var node_path
var dict
var vec3 What could be done however is to fully deprecate the CC @bojidar-bg @vnen |
IINM if you use Technically would be possible to do the same with export hints, but I'm not sure if it's wanted. |
It might be a generous thing to add a warning or error on export vars with hints and null values. I think the first impressions of it led me to expect empty NodePath to compare as null, because of how this was initially working. I understand everything much better now after bumbling around with it. @akien-mga I will add I found some issues (as of 2893b5a) with export vars currently that can make these things a bit more confusing. For example, a null export var with a float hint.
In the inspector you'll see this: If you print it out you get: I posted some issues detailing it a bit better, for them for anyone following here. It's all minor stuff, but there are some rough edges to this. |
Isn't this fixed by the new |
I guess so, because now you can only use the type hint to set the export type, so it should always default to an empty default value instead of |
Closing per @vnen's comment. |
Godot version: 3.1 custom
Issue description:
If a NodePath is exported and never assigned, its value will be null. If it is assigned and then cleared, the value will be an empty string.
Proposal:
Make the default value either be null or "" and document it
The text was updated successfully, but these errors were encountered: