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
It appears that the methods var_to_bytes_with_objects and bytes_to_var_with_objects do not work as expected when serializing and deserializing class instances. Specifically, properties of the instance revert to their initial values instead of retaining any changes made before serialization.
Steps to reproduce
Create an instance of a class.
Change a property of the instance.
Serialize the instance using var_to_bytes_with_objects.
Deserialize the instance using bytes_to_var_with_objects.
Observe that the deserialized instance's properties have reverted to their initial values.
Example Code
func_ready():
varinstance=RandomClass.new() # create a custom class that extends `Object`instance.thing="changed"varserialized=var_to_bytes_with_objects(instance)
vardeserialized: RandomClass=bytes_to_var_with_objects(serialized)
assert(deserialized.thing=="changed") # this will fail , and the value is "hello" as the default set in the class property definition
@dalexeev adding the @export_storage annotation works as expected , Thank you .. however i just find the documentation confusing a little bit when it says :
Note: Not all properties are included. Only properties that are configured with the @GlobalScope.PROPERTY_USAGE_STORAGE flag set will be serialized.
Then when we take a look at where this link goes :
PropertyUsageFlags PROPERTY_USAGE_STORAGE = 2
The property is serialized and saved in the scene file (default).
The way i interpreted the (default) is that this flag is already set by default for the class' properties. isn't it the case or am i missing something .
PROPERTY_USAGE_DEFAULT is used by default for exported properties, in _get_property_list(), etc. But by default, script variables are not exported at all:
Tested versions
4.3.beta2
System information
MacOS Sonoma, Compatibility Renderer
Issue description
It appears that the methods
var_to_bytes_with_objects
andbytes_to_var_with_objects
do not work as expected when serializing and deserializing class instances. Specifically, properties of the instance revert to their initial values instead of retaining any changes made before serialization.Steps to reproduce
var_to_bytes_with_objects
.bytes_to_var_with_objects
.Example Code
Minimal reproduction project (MRP)
test.zip
The text was updated successfully, but these errors were encountered: