-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Track source location in change detection #14034
Conversation
d3242ff
to
9ac216d
Compare
|
I really like this feature and think it'll be very useful, but I'll second the request for putting it behind an off-by-default feature flag. |
Yup, I assumed as much. I was hoping to get a read on whether this is even an acceptable approach to take for the feature. Before going down the path of adding feature flags. |
Is there a reason you're de referencing the static reference you get from |
Furthermore, why do you use |
The answer to most questions is probably going to be "because this is a proof of concept". 😄
For 2, it seems like it should be possible to get information from |
Is it possible to find the |
I would like this, one day :) Probably core + alloc, but still! Not a priority, but might as well do it when there's no cost to it. |
Yep, that would look like this (you'd also need to do the same for |
Good call! That looks pretty straightforward. |
Spent far to long trying to figure out why a camera transform from glb was getting reset, was correct on spawn, next frame its Identity, this found the issue in seconds. Was calling remove_parent_in_place before TransformPropagate had ran. Huge help. |
Co-authored-by: BD103 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this and I want it. Should Commands::add
and Command::push
be track_caller
so that custom user commands can provide call tracing? Or would that be something user should do on the methods of their extension trait.
It looks like this fully covers commands as well as direct world access. Except for the special paths that let you avoid change detection, is there anything that this can't track?
If we do want to support custom commands like this, it would need more documentation. I feel like this is probably follow-up PR territory. |
Fair enough, agreed. |
at the risk of sounding incredibly pedantic: 24 bytes. remember that this is a pretty magical struct that gets willed into existence by the compiler during codegen. I kinda expect it to have somewhat nonintuitive codegen properties because inspecting |
At best that would mean storing the caller location and changing In either case the problem for custom commands is that |
pub unsafe fn insert_resource_by_id( | ||
&mut self, | ||
component_id: ComponentId, | ||
value: OwningPtr<'_>, | ||
#[cfg(feature = "track_change_detection")] caller: &'static Location, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and insert_non_send_by_id
are the only pub functions that take Location
s (and also have a unused #[track_caller]
); they should be spit into a pub
version with #[track_caller]
and a pub(crate)
one that takes the caller.
Co-authored-by: Gino Valente <[email protected]>
I think so. This will be needed for custom impls, as you said. We can document the context around this on the |
#[cfg(feature = "track_change_detection")] | ||
{ | ||
*self.changed_by = Location::caller(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.set_changed
already updates the location
Hah, I forgot about wide pointers. Thanks! |
Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to bevyengine/bevy-website#1666 if you'd like to help out. |
Objective
Solution
track_caller
all the way up to the public API.Location::caller
, and pass this into the functions, instead of the functions themselves attempting to get the caller. This would not work for commands which are deferred, as the commands are executed by the scheduler, not the user's code.Testing
component_change_detection
example now shows where the component was mutated:Changelog
track_change_detection
flag.Migration Guide
changed_by
field to many internal ECS functions used with change detection when thetrack_change_detection
feature flag is enabled. Use Location::caller() to provide the source of the function call.