You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe this is not a bug but a documentation incompleteness.
While dict2inst function is setting values without using setter methods, inst2dict on the opposite calls get on every class field preventing any code-efficient way to store internal state of object (even simple data structure). Giving that there is no code-efficient way to clone objects either (return dict2inst(inst2dict(self)) is the only solution) this leads to severe problems with such simple operations as cloning and serializing objects with great (and constantly evolving) number of fields (since there is no way to manually manage serialization of 200-300 fields because of around 5 of them have getter methods).
demonstration code:
`
class test:
var value setget setter, getter
func setter(val):
print('setter called')
func getter():
print('getter called')
return value
func _init():
print('init called')
func _ready():
var tmp = test.new()
var dict = inst2dict(tmp)
var tmp2 = dict2inst(dict)
`
The text was updated successfully, but these errors were encountered:
Is the problem with getter methods consists of the possible side effects of calling such methods?
But 'side effects' of getter methods are the only reason they exist - cause without them getter do nothing above default getter (i.e. returning value directly). Still there are non-destructive side effects and there are logic-breaking side effects. For example, getter that do auto-converting some id to pooled object link (one of the simplest application) breaks working of serializing since there is no way to get to that id from list of properties. And since both trivial auto-serializing and customizable setters/getters are ones of the basic tools to proper system, it is very annoying (and clearly non-intuitive) that they are mutually incompatible.
Godot version: 3.1 stable
Maybe this is not a bug but a documentation incompleteness.
While dict2inst function is setting values without using setter methods, inst2dict on the opposite calls get on every class field preventing any code-efficient way to store internal state of object (even simple data structure). Giving that there is no code-efficient way to clone objects either (
return dict2inst(inst2dict(self))
is the only solution) this leads to severe problems with such simple operations as cloning and serializing objects with great (and constantly evolving) number of fields (since there is no way to manually manage serialization of 200-300 fields because of around 5 of them have getter methods).demonstration code:
`
class test:
var value setget setter, getter
func setter(val):
print('setter called')
func getter():
print('getter called')
return value
func _init():
print('init called')
func _ready():
var tmp = test.new()
var dict = inst2dict(tmp)
var tmp2 = dict2inst(dict)
`
The text was updated successfully, but these errors were encountered: