Skip to content

Make WorldId Hash and SparseSetIndex #7124

@recatek

Description

@recatek

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

Currently WorldId can't be hashed in HashMap or used as a key in a SparseSet within bevy. This makes it challenging to branch behavior based on specific worlds (e.g. doing things differently for different SubApps). WorldId just wraps a usize so this should be safe to do.

What solution would you like?

Implement/derive Hash and SparseSetIndex for World.

What alternative(s) have you considered?

Worlds could be semi-uniquely identified through other means, like having a unique resource, but adding utility to the world's ID seems like the most straightforward choice.

Additional context

This would be particularly useful for generalizing cross-app extract functions. This came up while I was trying to make a extract function manager between a parent and multiple SubApp worlds, like so:

SparseSet<WorldId, Vec<Box<Fn(&mut World, &mut World)>>>

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to use

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions