Replies: 3 comments 4 replies
-
I have a binary serializer (which uses Serializing Nodes and built-in Resource types is possible, but I can tell that de-serializing some built-in types does not go smoothly, as there are properties that might result in an error when set depending on other properties. That is, the order in which you set them matters. At which point it is better to make a dedicated serializer for the particular type. Besides, often we want to serialize custom types anyway. The method You can use I don't know why these methods would be giving you Assuming you got a |
Beta Was this translation helpful? Give feedback.
-
I just tried recreating what I was doing with get_script() in new code, and it seems to be working now. I was doing was creating a new instance of my object and then calling get_script() on it sometime later. I'm not sure what was going wrong. |
Beta Was this translation helpful? Give feedback.
-
Have you tried |
Beta Was this translation helpful? Give feedback.
-
I'm trying to set up a multiplayer game and running into issues trying to send objects over the network. At the moment, the RPC calls will only let you send primitives which makes trying to send a data structure with any complexity a real pain. What would be helpful is to provide a way to serialize simple Resource objects to a PackedByteArray or something similar. This could be easily sent across a network or saved to disk. While you wouldn't be able to serialize Nodes, it should be possible to serialize objects that only have fields that are primitives or objects that are similarly simple.
I looked into ResourceSaver, but this only saves to disk, not of a PackedByteArray or String. I also tried writing my own serializer using reflection, but I am unable to determine the script name of my object so I don't know what to create when it's time to deserialze the object (get_class() and get_script() are both returning null).
Anyhow, a serializer for simple objects would be really useful.
Edit:
I could give writing my own reflection based serializer another shot, but I really am having trouble trying to figure out what the data type of my object is through reflection. Why is get_script() returning null? I can see the script set in the inspector. Some other forum posts recommend overriding get_class() with your script's class name, and that may have worked in Godot 3, but in Godot 4 it causes an error. How do I get the script name of my object?
Beta Was this translation helpful? Give feedback.
All reactions