bevyengine / bevyengine/bevy

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

Open
#21,805 1 comment 0 reactions 0 assignees View on GitHub
A-ECS A-Networking A-Scenes C-Docs D-Modest S-Ready-For-Implementation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

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:
```rust
#[derive(Component, Reflect)]
#[reflect(Component)]
struct MyComponent {
#[entities]
entity: Entity
}
```
works for components,
but the same thing does NOT work for resources
```rust
#[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:
```rust
#[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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.