Can't serialize `DynamicScene` containing asset loaded from a path
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version and features
v0.17
## What you did
- `let handle = asset_server.load("some/font.ttf");`.
- Add asset to scene (via handle) through `TextFont`.
- Serialize scene through `DynamicScene` with code below.
```rust
let prefab_scene = DynamicSceneBuilder::from_world(world)
// Never serialize resources in a prefab
.deny_all_resources()
// Extract non-root entities regularly
.extract_entities(indirect)
// Extract root entities without any `Children`
.deny_component::()
.extract_entities(roots.iter().cloned())
// Finish and build the actual prefab scene
.build();
let serialized_scene = {
let tr = type_registry.read();
prefab_scene.serialize(&*tr).unwrap()
};
```
## What went wrong
Can't serialize strong handle.
```
called `Result::unwrap()` on an `Err` value:
Message("type `bevy_platform::sync::Arc` did not register
the `ReflectSerialize` or `ReflectSerializeWithRegistry` type data.
For certain types, this may need to be registered manually using `register_type_data`
(stack:
`bevy_text::text::TextFont`
-> `bevy_asset::handle::Handle`
-> `bevy_platform::sync::Arc`)")
```
## Additional information
If the font asset was loaded from a path, I expect the serialization of the scene to generate a reference to that font path so that the scene asset, after being saved and reloaded, on load can also trigger the loading of the font asset as a dependency. That way I can serialize a scene referencing assets like fonts, textures, etc. Otherwise that means I can't serialize a scene with asset references?
I understand that creating assets via code doesn't work because currently we can't assign a path. But I expected that for assets loaded from disk from a path, at least the path was set on the asset, and that therefore it was useable for serialization. I consider that assets always have shared ownership, so should never be embedded into another asset. I think there are cases where you'd want embedding (e.g. mesh inside glTF), but those should be an exception, not the default. The design of `Handle` is that strong handles are reference-counted, which semantically means shared ownership.
Contributor guide
Assessment
This issue has not been assessed yet.