Expose more `MaybeLocation` parameters/fields
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## What problem does this solve or what need does it fill?
In my crate I would like to pass `#[track_caller]` to entity mutations/commands. That way, when users of my crate want to debug things, they see the location where they indirectly, through my crate, updated components or spawned entities. But that is not possible as all methods are `pub(crate)` in bevy's source. One would only see where I call them, with no information for the user where they call my stuff.
I have the most issues with closures where the operations happen. But `#[track_caller]` does not work for closures. See: https://github.com/rust-lang/rust/issues/87417
## What solution would you like?
Find a way to pass `MaybeLocation` into the API. I understand this would explode the API further which is why I did not just make a PR.
But maybe this issue can serve as a place for discussing what can be done here.
## What alternative(s) have you considered?
I considered working with the standalone entity commands to somehow do get the location into the place I want. For example instead of using `EntityWorldMut::insert` somewhere deep down in my closures, I use `entity_commands::insert` at the top level to generate a command _with_ the current caller and pass that command down to my closures to apply it.
This however only works if I know what operation I want to do at the top scope, which is not often the case. Also not every `EntityWorldMut` method exists as a standalone command.
An alternative idea could be to offer an API to overwrite the `MaybeLocation`s stored by bevy.
Contributor guide
Research direction
Start by reviewing Bevy's MaybeLocation handling and the entity mutation and command APIs, especially EntityWorldMut and standalone entity_commands. Compare how caller locations are currently propagated and determine what public API shape would support the requested operations; done means a decided, documented approach that enables callers to preserve or overwrite MaybeLocation values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend-api-design, game-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100