Skip to content

Custom serialization for Entity #386

@LPGhatguy

Description

@LPGhatguy

This issue is rough spitballing for how hecs might allow users to define how Entity gets serialized/deserialized.

hecs has been fantastic for our game and we've had a good serialization solution for a long time. One of the warts in our integration, however, is that we have two versions of the Entity type in order to support a custom implementation of Serialize and Deserialize. All of our components use our wrapped version and they automatically get remapped to integers or strings when appropriate during serialization.

In some places, we're able to easily wrap the hecs APIs to only return our custom Entity type, but hecs::Entity usually ends up leaking out. We call that type EphemeralEntity to emphasize that it's meant to be for non-serialized data, but I'd rather not have that type at all!

One option is for us to keep a small fork of hecs where we change the implementation of Serialize and Deserialize on Entity to go through our remapping process. It probably wouldn't be a very big patch, but then we're out of "userspace" hecs which is kind of lame.

A large hammer of an API would be for hecs to expose a global that a user could override in order to implement Serialize and Deserialize. Maybe that'd be in the form of a trait object that mirror's #[serde(with = ...)] and uses erased_serde.

I'm down for any other options in this space that lead to us being able to delete the wrapper around hecs::Entity in our codebase. 😅

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions