Skip to content

Make `dict2inst` to work with arbitrary `_init` parameters

Andrii Doroshenko requested to merge github/fork/Xrayez/fix-dict2inst-init into master

Fixes #30572.

This is achieved by skipping initializer call while creating an instance of a GDScript. This is implemented by passing -1 as an argument count to _new and interpreting any value below 0 to mean that the initializer should not be called during instantiation, because internal members of an instance are going to be overridden afterwards (from a dictionary).

I'm not sure if the initializer should actually be called, but it doesn't make sense to me because this is mostly done for deserialization, so I think this should do it. In fact, I don't see a way to call the initializer without knowing what are the actual arguments for parameters, unless you somehow store the initial arguments beforehand when an instance is created normally with script.new(vararg) for them to be stored directly inside dictionary created with inst2dict.

I'd be more adventurous in making more thorough changes but I'd like to hear what you think of this, or whether you see a better fix. Namely, creation and construction would need to be refactored and treated separately.

Merge request reports