Make inst2dict and dict2inst work recursively
Closes #6533.
This makes inst2dict
GDScript method to turn inner instances present as properties to be converted to a dictionary recursively, including instances with nested arrays and dictionaries with key/value pair.
Added a deep
paramater to inst2dict
so that the default behavior remains the same. Recursive conversion is disabled by default because instances may have circular references as described in https://github.com/godotengine/godot/issues/31229#issuecomment-519955042, hence must be used with caution on case-to-case basis. Updated documentation accordingly.
Features
-
Convert properties with instances (inner classes) recursively using inst2dict
. -
Convert nested arrays with classes recursively using inst2dict
. -
Convert nested dictionaries with classes recursively. -
Convert all back using dict2inst
(all above). -
Add recursive/deep
option forinst2dict
method.
Test project
Extensive test project demonstrating all of the added features, and showing how having circular references fail, which is handled in debug builds by checking that only unique objects are converted.