godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.3k stars 20.23k forks source link

GDScript: get_property_default_value always returns Null #40122

Open me2beats opened 4 years ago

me2beats commented 4 years ago

Godot version:

3.2.2 stable

OS/device including version:

Windows

Issue description:

return the property default value, getting Null instead

Steps to reproduce:

var a = 1
func _ready():
    print (get_script().get_property_default_value("a"))

Minimal reproduction project:

not required

pouleyKetchoupp commented 4 years ago

From what I can see, this method is not usable in its current state (apart from the current issue, it's implemented for the editor only, so it does nothing in an exported game).

When adding print(get_script().get_script_property_list()) to the same script, the output is: [{class_name:, hint:0, hint_string:, name:a, type:0, usage:8192}]

So it would make sense for get_property_default_value() to return the expected value.

This method needs to be functional, unexposed from scripts or better documented.

Link to the doc: https://docs.godotengine.org/en/stable/classes/class_script.html#class-script-method-get-property-default-value

akien-mga commented 4 years ago

It should probably be unexposed. It's probably not doing what you expect it to do - for var a = 1, it would likely return the default value of Variants, which is indeed null. var a = 1 assigns a value, but not a "default" value as meant in this method, which is used to define what properties can revert to in the Inspector.

CC @bojidar-bg

me2beats commented 4 years ago

that is, if I understood correctly this method cannot be used in GDScript?

then imo this should at least be stated in the documentation (that this method cannot be used in gdscript).

yankscally commented 1 month ago

This is still around in 4.3, btw.

Would really like a method for this, and to remove the current method. The docs don't really explain what this method is really doing.

The default value of Variant being null seems to be not that useful, but actually getting the default value (as you would expect by the name) would be more useful.