-
-
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
[Merged by Bors] - fix parenting of scenes #2410
Conversation
Could we add a test for this? |
Not easily possible to add a test, at least as a unit test: it would need to access assets, which can't be added without the asset server, which needs a thread pool... this is more an integration test, and I would rather not add those at the moment |
I would argue and say then, we should start to add integration testing haha 😄 |
I'm happy not to block this PR on testing, however, we should seriously consider integration testing for scenarios like this. |
let children = &**children; | ||
let mut children = children.to_vec(); | ||
children.push(entity); | ||
parent_entity.insert(Children::with(&children)); |
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 seems like quite a bit of vector coppying.
Is it possible to just push entity
to the parent's children component?
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.
the SmallVec
inside Children
is not mutably accessible because it caused a lot of sync issues:
pub struct Children(pub(crate) SmallVec<[Entity; 8]>); |
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 think it would be nice to add a comment about this?
let children = &**children; | ||
let mut children = children.to_vec(); | ||
children.push(entity); | ||
parent_entity.insert(Children::with(&children)); |
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 think it would be nice to add a comment about this?
if !entity_mut.contains::<Parent>() { | ||
entity_mut.insert(Parent(parent)); | ||
} | ||
} | ||
// Add the scene root to the `Children` component on the parent | ||
if let Some(mut parent_entity) = world.get_entity_mut(parent) { |
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 feels like quite the hack, both because we're duplicating parenting logic in scenes and because of the children copy. I want to fix this bug, but maybe we need a slightly more holistic solution. Hard-coding logic here seems like a reasonable short term fix (with a TODO to improve this later), but reallocating Children for each child in a scene is hard to accept. One way to implement this without directly exposing internals is to add a new AddChild
command to bevy_transform
, which takes advantage of crate-only access to the Children internals. Then you could just construct the Command for each entity and immediately apply it (no need for command buffers / allocations).
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.
(AddChild would transactionally set the proper values for the Parent and Children components)
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.
added AddChild
command. It's the only command with pub fields to be able to create and execute it directly
b7be890
to
6fc5c49
Compare
bors r+ |
# Objective Fix #2406 Scene parenting was not done completely, leaving the hierarchy maintenance to the standard system. As scene spawning happens in stage `PreUpdate` and hierarchy maintenance in stage `PostUpdate`, this left the scene in an invalid state parent wise for part of a frame ## Solution Also add/update the `Children` component when spawning the scene. I kept the `Children` component as a `SmallVec`, it could be moved to an `HashSet` to guarantee uniqueness Co-authored-by: François <8672791+mockersf@users.noreply.github.com>
Build failed: |
bors r+ |
# Objective Fix #2406 Scene parenting was not done completely, leaving the hierarchy maintenance to the standard system. As scene spawning happens in stage `PreUpdate` and hierarchy maintenance in stage `PostUpdate`, this left the scene in an invalid state parent wise for part of a frame ## Solution Also add/update the `Children` component when spawning the scene. I kept the `Children` component as a `SmallVec`, it could be moved to an `HashSet` to guarantee uniqueness Co-authored-by: François <8672791+mockersf@users.noreply.github.com>
Build failed (retrying...): |
# Objective Fix #2406 Scene parenting was not done completely, leaving the hierarchy maintenance to the standard system. As scene spawning happens in stage `PreUpdate` and hierarchy maintenance in stage `PostUpdate`, this left the scene in an invalid state parent wise for part of a frame ## Solution Also add/update the `Children` component when spawning the scene. I kept the `Children` component as a `SmallVec`, it could be moved to an `HashSet` to guarantee uniqueness Co-authored-by: François <8672791+mockersf@users.noreply.github.com>
Build failed: |
bors r+ |
# Objective Fix #2406 Scene parenting was not done completely, leaving the hierarchy maintenance to the standard system. As scene spawning happens in stage `PreUpdate` and hierarchy maintenance in stage `PostUpdate`, this left the scene in an invalid state parent wise for part of a frame ## Solution Also add/update the `Children` component when spawning the scene. I kept the `Children` component as a `SmallVec`, it could be moved to an `HashSet` to guarantee uniqueness Co-authored-by: François <8672791+mockersf@users.noreply.github.com>
Build failed (retrying...): |
# Objective Fix #2406 Scene parenting was not done completely, leaving the hierarchy maintenance to the standard system. As scene spawning happens in stage `PreUpdate` and hierarchy maintenance in stage `PostUpdate`, this left the scene in an invalid state parent wise for part of a frame ## Solution Also add/update the `Children` component when spawning the scene. I kept the `Children` component as a `SmallVec`, it could be moved to an `HashSet` to guarantee uniqueness Co-authored-by: François <8672791+mockersf@users.noreply.github.com>
Build failed: |
bors r+ |
# Objective Fix #2406 Scene parenting was not done completely, leaving the hierarchy maintenance to the standard system. As scene spawning happens in stage `PreUpdate` and hierarchy maintenance in stage `PostUpdate`, this left the scene in an invalid state parent wise for part of a frame ## Solution Also add/update the `Children` component when spawning the scene. I kept the `Children` component as a `SmallVec`, it could be moved to an `HashSet` to guarantee uniqueness Co-authored-by: François <8672791+mockersf@users.noreply.github.com>
Pull request successfully merged into main. Build succeeded: |
Objective
Fix #2406
Scene parenting was not done completely, leaving the hierarchy maintenance to the standard system. As scene spawning happens in stage
PreUpdate
and hierarchy maintenance in stagePostUpdate
, this left the scene in an invalid state parent wise for part of a frameSolution
Also add/update the
Children
component when spawning the scene.I kept the
Children
component as aSmallVec
, it could be moved to anHashSet
to guarantee uniqueness