Open Zylann opened 5 years ago
Based on my findings, it does assume that an object has GDScript
attached specifically. It uses internal GDScriptInstance
as an interface to an object with the script, traversing all script members.
Also it's difficult to tell what kind of properties need to be serialized if it's not based on a script. The question is whether inst2dict
should accept an optional array of properties that you're interested in serializing, alongside script properties of course.
inst2dict
could also be generalized to handle any object in the future indeed, which doesn't have to be based on a script: https://github.com/godotengine/godot/issues/6533#issuecomment-320896833:
And also they should could be used for all of script languages instead of GDScript only.
Also it's difficult to tell what kind of properties need to be serialized if it's not based on a script.
Same as with a script I assume? Properties having PROPERTY_HINT_STORAGE
. Note: export
== PROPERTY_HINT_STORAGE | PROPERTY_HINT_EDITOR
I should also note that inst2dict
serializes both export
ed and regular properties.
Properties having PROPERTY_HINT_STORAGE
Is it possible to override this for built-in properties then? I've seen _get_property_list()
is used for that but I'm not sure.
I'm also not sure if a user would want to automatically serialize built-in properties along with script properties by default.
I personally have no real use for this at the moment so I'd be fine if inst2dict
documentation covers all those cases, because right now there are inconsistent exceptions like this one. If someone wants to use it on non-script instances we'd have to figure it out.
Still valid in dfed88b
Still valid today: the below throws an error.
var sprite = Sprite2D.new()
print(inst_to_dict(sprite))
Godot 3.1.1
The following does not work:
Error:
Is there a reason why the object must have a script on it? Either way, if it's intented it should also be documented.