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
Describe the bug
While trying to get equipment system working, I've noticed an issue with serialization of Reference properties.
Apparently, using set_reference() on an entity instance with a reference property and then calling Pandora.serialize(...) results in that property being serialized as an object, instead of a Dictionary, which causes problems when trying to process serialized data further.
To Reproduce
Consider an example project with this setup in Pandora as an example (ignore weird styling on dropdowns - I was messing with editor theme):
Initial reference in Helmet property is left empty.
Now, we run this code:
extendsNode@exportvarcharacter: Character# extends PandoraEntity - Player entity is assigned@exportvaritem: HelmetItem# extends Item extends PandoraEntity - Simple Helmet entity is assignedfunc_ready() ->void:
varinstance:=character.instantiate()
instance.set_reference("Helmet", item)
varserialized:=Pandora.serialize(instance)
print(serialized)
# prints: { "_id": "8", "_instanced_from_id": "8", "_instance_properties": [{ "_value": <PandoraEntity 'Simple Helmet'>, "_property_id": "7" }], "_index": 0 }varserialized_json:=JSON.stringify(serialized)
print(serialized_json)
# prints: {"_id":"8","_index":0,"_instance_properties":[{"_property_id":"7","_value":"<PandoraEntity 'Simple Helmet'>"}],"_instanced_from_id":"8"}vardeserialized_instance:=Pandora.deserialize(JSON.parse_string(serialized_json))
deserialized_instance.get_reference("Helmet")
# Error: "Trying to assign a non-object value to a variable of type 'entity.gd'."
As you can see from the serialized Dictionary, Helmet property is serialized as { "_value": <PandoraEntity 'Simple Helmet'>, "_property_id": "7" } and when stringified to JSON it becomes a string, which is completely incorrect and causes an error in get_reference() method when trying to access that property after deserialization.
Expected behavior
Reference property is properly serialized.
Desktop (please complete the following information):
I hit this a week or two ago, definitely not the expected behavior! A non-ideal workaround I went with was to use a string entity_id and fetching 'relations' with that id in the code. I didn't like it, but it doesn't leak too far if you're already writing a custom entity class:
Godot version: 4.2.1
Describe the bug
While trying to get equipment system working, I've noticed an issue with serialization of Reference properties.
Apparently, using
set_reference()
on an entity instance with a reference property and then callingPandora.serialize(...)
results in that property being serialized as an object, instead of a Dictionary, which causes problems when trying to process serialized data further.To Reproduce
Consider an example project with this setup in Pandora as an example (ignore weird styling on dropdowns - I was messing with editor theme):
Initial reference in Helmet property is left empty.
Now, we run this code:
As you can see from the serialized Dictionary,
Helmet
property is serialized as{ "_value": <PandoraEntity 'Simple Helmet'>, "_property_id": "7" }
and when stringified to JSON it becomes a string, which is completely incorrect and causes an error inget_reference()
method when trying to access that property after deserialization.Expected behavior
Reference property is properly serialized.
Desktop (please complete the following information):
Additional context
Minimal reproduction project:
PandoraReferenceSerializationBug.zip
The text was updated successfully, but these errors were encountered: