-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Ensure GlobalTransform
consistency when Parent
is spawned without Children
#3340
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use crate::components::{Children, GlobalTransform, Parent, Transform}; | ||
use crate::components::{Children, DirtyParent, GlobalTransform, Parent, Transform}; | ||
use bevy_ecs::{ | ||
entity::Entity, | ||
prelude::Or, | ||
query::{Changed, With, Without}, | ||
system::Query, | ||
}; | ||
|
@@ -13,7 +14,7 @@ pub fn transform_propagate_system( | |
Without<Parent>, | ||
>, | ||
mut transform_query: Query<(&Transform, &mut GlobalTransform), With<Parent>>, | ||
changed_transform_query: Query<Entity, Changed<Transform>>, | ||
changed_transform_query: Query<Entity, Or<(Changed<Transform>, With<DirtyParent>)>>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'm not actually sure that (without doing that) any changes to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did have a discussion about this when implementing it. The options were:
My preference was 1. or 2. The reasoning was that IMO, it shouldn't really trigger a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose what actually needs to happen is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't quite follow; could you please elaborate? I think in general There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well my point is: if you add a chilld, how does the child's transform get updated? Neither the parent or child's transforms have changed, so that filter won't activate; so changed will be If you don't want to update 'self''s transform then, the way to implement this would be to add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK I don't understand the solution at all; at least I can't think of a way of doing it without recalculating the siblings which haven't changed. This is how I think that the algorithm currently works.
In the problematic case, the The
I cannot see how a single |
||
children_query: Query<Option<&Children>, (With<Parent>, With<GlobalTransform>)>, | ||
) { | ||
for (entity, children, transform, mut global_transform) in root_query.iter_mut() { | ||
|
@@ -40,7 +41,7 @@ pub fn transform_propagate_system( | |
|
||
fn propagate_recursive( | ||
parent: &GlobalTransform, | ||
changed_transform_query: &Query<Entity, Changed<Transform>>, | ||
changed_transform_query: &Query<Entity, Or<(Changed<Transform>, With<DirtyParent>)>>, | ||
transform_query: &mut Query<(&Transform, &mut GlobalTransform), With<Parent>>, | ||
children_query: &Query<Option<&Children>, (With<Parent>, With<GlobalTransform>)>, | ||
entity: Entity, | ||
|
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 feel like this comment is more appropriate on the struct declaration. Right now the only explanation as to what
DirtyParent
means is here but the struct itself has no documentation.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'm not certain the struct declaration is a great place for this particular bit of documentation -
DirtyParent
is a quirk of both theparent_update_system
and how the stages are currently run; the comment is there because it's not obvious why you'd add it in that particular code branch.As to the wider point, I don't know what the documentation on the declaration should achieve. The problem is quite a niche one - you need to spawn your components in a particular way and even then, you'll only touch
DirtyParent
in the specific case that you're running a system in the same stage. If you're looking atDirtyParent
directly, it's likely that you'll want to read through the code itself.Arguably it should be part of the documentation on the whole hierarchy system, since that would be where the "entrypoint" to this behaviour would be.