Skip to content

How to serialize/deserialize a resource that holds Entities (ie MapEntities) #21805

@Sheldonfrith

Description

@Sheldonfrith

Nowhere that I can find in the documentation, online tutorials, or the official examples shows how to correctly set up a resource struct for serialization/deserialization when it holds entities that need to be mapped to the new world.

The documentation for components is also in a very bad state, in regards to entity mapping, but I was able to figure it out by searching through the discord server at least. Not so for resources.

For example:

#[derive(Component, Reflect)]
#[reflect(Component)]
struct MyComponent {
#[entities]
entity: Entity
}

works for components,
but the same thing does NOT work for resources

#[derive(Resource,Reflect)]
#[reflect(Resource)]
struct MyResource{
#[entities]
entity:Entity
}

The compiler says : cannot find attribute `entities` in this scope `entities` is an attribute that can be used by the derive macros `Component` and `MapEntities`, you might be missing a `derive` attributer

This, which I found on discord, also doesn't work:

#[derive(Resource,MapEntities,Reflect)]
#[reflect(Resource)]
#[reflect(MapEntities)]
struct MyResource{
#[entities]
entity:Entity
}

Knowing how to do this is pretty essential for my application, and I image for many other serious bevy users as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsA-NetworkingSending data between clients, servers and machinesA-ScenesSerialized ECS data stored on the diskC-DocsAn addition or correction to our documentationD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions