Beginner Guide's: Serialization and Deserialization

Code Beginner Guide's: Serialization and Deserialization

Q: Can I skip serialization for some fields?
A: Only if the field is meant to reset on every server reboot (like temporary runtime-only values). Otherwise, leave it out at your own risk.




Q: Do I need to serialize fields like Name, Hue, or Weight?
A: No, because the base Item class already saves those. You only need to serialize your own custom fields.




Q: Can I use BinaryWriter or C#'s built-in serialization?
A: Not with ServUO’s save system. You must use GenericWriter and GenericReader, or it won't be saved properly.




Q: What happens if I change the order of fields in Serialize/Deserialize?
A: Don’t. Seriously. The read and write order must match exactly — otherwise, the server will load garbage data or crash.




Q: Can I safely remove fields later?
A: Yes, but only if you're using versioning and you handle it carefully. Keep the older reads behind a version check even if you no longer use the field.




Q: How do I make my own serializable object (like a helper class)?
A: Create a class that implements ISerializable and add a public void Serialize(GenericWriter writer) and public void Deserialize(GenericReader reader) method to it.




Q: Is there a limit to what I can serialize?
A: Practically, yes. Avoid saving overly large lists, massive objects, or recursive structures. Keep save/load operations lightweight and quick.




Q: How do I handle backwards compatibility with older save files?
A: Always use versioning, and never remove the reader.ReadX() calls for fields that were saved in older versions, even if the field is no longer used.

Active Shards

Donations

Total amount
$0.00
Goal
$500.00
Back