I think I have missed something too obvious for me to see, or that I'm misunderstanding the capabilities of this library.
I have an object with a nested object. This should be able to serialise/deserialise, right?
class Outer:
var first: String
var inner: Inner
func _init(first: String, inner: Inner):
self.first = first
self.inner = inner
func _get_constructor_args():
return [first, inner]
class Inner:
var apples: int
var oranges: int
func _init(apples: int, oranges: int):
self.apples = apples
self.oranges = oranges
func _get_constructor_args():
return [apples, oranges]
func test_outer_inner():
ObjectSerializer.register_script("Outer", Outer)
ObjectSerializer.register_script("Inner", Inner)
var test = Outer.new("hello", Inner.new(123, 456))
var ser = BinarySerializer.serialize_var(test)
var bytes = var_to_bytes(ser)
var des = bytes_to_var(bytes)
var result = BinarySerializer.deserialize_var(des)
print("Result", result)
Yields this error:
Report:
line 132: Godot Runtime Error !
'at: _ScriptRegistryEntry.deserialize (res://addons/godot_object_serializer/object_serializer.gd:132)'
Error: 'Invalid call. Nonexistent function 'has_method' in base 'Nil'.'
object_serializer.gd:
var instance: Variant
if value.has(ObjectSerializer.args_field):
instance = script_type.new.callv(value[ObjectSerializer.args_field]) <---- this returns null
else:
instance = script_type.new()
var excluded_properties: Array[String] = []
if instance.has_method("_get_excluded_properties"): <------ error at this line, instance is null
excluded_properties = instance._get_excluded_properties()
What am I doing wrong?
I think I have missed something too obvious for me to see, or that I'm misunderstanding the capabilities of this library.
I have an object with a nested object. This should be able to serialise/deserialise, right?
Yields this error:
object_serializer.gd:
What am I doing wrong?