Skip to content

Impl FromWrold for Handle<T> #6525

@PhaestusFox

Description

@PhaestusFox

What problem does this solve or what need does it fill?

currently loading Handles from dynamic scenes loaded from a file will give you a weak handle. it would be nice if handles loaded this way were strong so that you don't have to keep a strong handle somewhere else to prevent assets from unloading that are in the scene. this would be necessary if we wanted to store asset dependency paths in scenes.

What solution would you like?

  1. Remove the Default implementation for Handle; use Handle::weak instead for this functionality
  2. impl FromWrold for Handle; Access Asset so handle can be strong
  3. Add set_id method that decrements the current id and increments the new id

What alternative(s) have you considered?

This could also be done with the ReflectComponent implementation but would take significantly more work since that is (as far as I could tell) all auto-implemented with generics.

Additional Info

it would also allow for a nice expansion of dynamic scenes when serialised we could add to the API

fn save_world(
    world: &World,
    asset_server: Res<AssetServer>,
    type_registry: Res<TypeRegistry>,
) {
    let scene = DynamicScene::from_world(world, &type_registry);
    let ron = scene.serialize_ron_with_dependencys(&type_registry, &asset_server);
    std::fs::write("./assets/scene.scn.ron", ron).unwrap();
}

this would require the asset server and extract any paths that the handles came from

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AssetsLoad files from disk to use for things like images, models, and soundsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useD-ComplexQuite challenging from either a design or technical perspective. Ask for help!

    Type

    No type

    Projects

    Status

    Concrete and Controversial

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions