Skip to content

Add World::resource_scope_by_id  #13466

Open
@Shatur

Description

@Shatur

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

I working on https://github.com/projectharmonia/bevy_replicon and we do a lot of type erasure internally for perfomance and a nice API.

Sometimes I need to access a resource mutably by ID and other resources just as reference. Since we don't have something like World::resource_scope_by_id, I do the inverse:

world.resource_scope(|world, registry: Mut<AppTypeRegistry>| {
    world.resource_scope(|world, entity_map: Mut<ServerEntityMap>| {
        world.resource_scope(|world, server_events: Mut<ServerEvents>| {
        });
    });
});

What solution would you like?

But it would be nicer to do it like this:

world.resource_scope_by_id(id, |world, resource| {
    let mut registry = world.resource::<AppTypeRegistry>();
    let mut entity_map = world.resource::<ServerEntityMap>();
    let mut server_events = world.resource::<ServerEvents>();
    // ...
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!X-UncontroversialThis work is generally agreed upon

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions