Skip to content

Conversion of EntityMut into EntityRef #5459

@Moulberry

Description

@Moulberry

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

If a function exists that takes an EntityRef, it would be nice to be able to call this function using an EntityMut.
Currently, this is not possible and you have to do a second lookup to get the EntityRef you need.

What solution would you like?

Add a function, like the following, onto EntityMut:

pub fn to_ref(self) -> EntityRef {
    EntityRef {
        world: self.world,
        entity: self.entity,
        location: self.location
    }
}

Could be implemented like this, or by leveraging From

What alternative(s) have you considered?

Shared super-trait for EntityRef and EntityMut, though this is more complicated and would force use of generics unnecessarily

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-TrivialNice and easy! A great choice to get started with Bevy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions