[Merged by Bors] - fix parenting of scenes#2410
[Merged by Bors] - fix parenting of scenes#2410mockersf wants to merge 5 commits intobevyengine:mainfrom
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.
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.
the SmallVec inside Children is not mutably accessible because it caused a lot of sync issues:
There was a problem hiding this comment.
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.
I think it would be nice to add a comment about this?
| } | ||
| } | ||
| // 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.
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.
(AddChild would transactionally set the proper values for the Parent and Children components)
There was a problem hiding this comment.
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
PreUpdateand hierarchy maintenance in stagePostUpdate, this left the scene in an invalid state parent wise for part of a frameSolution
Also add/update the
Childrencomponent when spawning the scene.I kept the
Childrencomponent as aSmallVec, it could be moved to anHashSetto guarantee uniqueness