-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It would be nice if Bevy had a commands.entity_option() that returned a Option<EntityCommands<'w, 's, 'a>> #3757
Comments
This is an interesting idea. It's closely related to #2004, but not a duplicate. In terms of naming, I'd probably lean towards I'm not sure that this gives quite the behavior you want though: the various commands work on |
This is error handling for the easy case where the given entity doesn't actually exist. Fwiw, I think That would just be: pub fn try_entity(&mut self, entity: Entity)->Option<EntityCommands> {
self.entities.contains(entity).then(|| self.entity(entity))
} |
It seems like the convention is to use "get" in the name of methods that optionally return things from a collection, especially when there is a non-optional lookup that panics. |
Seeing as how in World, it is called World::get_entity(), maybe that is the convention we should follow? I probably should not have proposed a name... just pointing out the need for a way to do this. |
What problem does this solve or what need does it fill?
Sometimes commands.entity(entity_id) panics because the entity is already unspawned.
What solution would you like?
commands.entity_option(...) that returns a Option<EntityCommands<'w, 's, 'a>> ... this would be a workaround for commands.entity(...) that can panic.
What alternative(s) have you considered?
panic::catch_unwind doesn't work.
Additional context
Getting the world with exclusive_system to use get_entity doesn't work in my case.
The text was updated successfully, but these errors were encountered: