You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a simple explanation, suppose I have a world entity with parent/child components. I want to update its transform component with a DynamicScene using a previously initialized EntityMap that maps the entity from the dynamic scene to the world. The dynamic scene only contains this transform component. When I do DynamicScene.write_to_world, bevy panics.
This is NOT related to issue #6573, and was also there in Bevy 0.8.1.
As a side note, the error handling seems incorrect, It unwraps/panics instead of returning Result.
I expect write_to_world to only update the components that are included within the DynamicScene.
I also expect that in case of an error, the function will return Result and will not panic.
what actually happened?
DynamicScene panics on write_to_world due to remapping the valid references in child/parent components.
If an entity is present in the EntityMap, its child/parent entities are remapped on every call regardless of whether the entity is present in the DynamicScene that we are inserting into the world. Basically, when the entity is already present in the world with the correct parents/children, this code tries to remap already valid values (provided that the entity mapping is present in the EntityMap).
Additional information
I am trying to do real-time network scene updates by transferring updated components only. First I transfer the whole world as a serialized dynamic scene which initializes EntityMap that I store. In later updates, I only transfer updated components and reuse the EntityMap. I use write_to_world to directly to update the world. Looking at the implementation, write_to_world was made to be able to update existing entities.
In my case I apply a dynamic scene to an existing entity. If the parent of that existing entity is entity 0, it will remap it thinking it comes from the dynamic scene.
The MapEntities implementations have checks trying to prevent this. For the Parent component there is a check if the parent entity matches one in the dynamic scene. The problem is: an entity 0v0 can exist in a dynamic scene (and will in most cases) and in the world at the same time (the first world entity). This makes the entity check incorrect in some circumstances.
A possible solution would be using a special entity generation for entities from dynamic scenes, ensuring that no scene entity will conflict with one already in the world.
sQu1rr
changed the title
DynamicScene.write_to_world panics when on partial updates involving hierarchies
DynamicScene.write_to_world panics when on updates involving hierarchies
Nov 20, 2022
sQu1rr
changed the title
DynamicScene.write_to_world panics when on updates involving hierarchies
DynamicScene.write_to_world panics on updates involving hierarchies
Nov 20, 2022
sQu1rr
changed the title
DynamicScene.write_to_world panics on updates involving hierarchies
DynamicScene.write_to_world panics on partial updates involving hierarchies
Nov 20, 2022
Bevy version
Bevy 0.9.0
What you did
For a simple explanation, suppose I have a world entity with parent/child components. I want to update its transform component with a
DynamicScene
using a previously initializedEntityMap
that maps the entity from the dynamic scene to the world. The dynamic scene only contains this transform component. When I doDynamicScene.write_to_world
, bevy panics.This is NOT related to issue #6573, and was also there in Bevy 0.8.1.
As a side note, the error handling seems incorrect, It unwraps/panics instead of returning Result.
bevy/crates/bevy_scene/src/dynamic_scene.rs
Line 100 in e0c3c6d
What went wrong
what were you expecting?
I expect
write_to_world
to only update the components that are included within theDynamicScene
.I also expect that in case of an error, the function will return Result and will not panic.
what actually happened?
DynamicScene
panics onwrite_to_world
due to remapping the valid references in child/parent components.If an entity is present in the EntityMap, its child/parent entities are remapped on every call regardless of whether the entity is present in the DynamicScene that we are inserting into the world. Basically, when the entity is already present in the world with the correct parents/children, this code tries to remap already valid values (provided that the entity mapping is present in the EntityMap).
Additional information
I am trying to do real-time network scene updates by transferring updated components only. First I transfer the whole world as a serialized dynamic scene which initializes EntityMap that I store. In later updates, I only transfer updated components and reuse the EntityMap. I use write_to_world to directly to update the world. Looking at the implementation, write_to_world was made to be able to update existing entities.
Remapping happens here:
bevy/crates/bevy_scene/src/dynamic_scene.rs
Line 99 in e0c3c6d
For all entities in the EntityMap:
bevy/crates/bevy_ecs/src/reflect.rs
Line 426 in e0c3c6d
The actual error is generated here:
bevy/crates/bevy_hierarchy/src/components/children.rs
Line 26 in e0c3c6d
Examples
A simplified example that breaks right away: https://pastebin.com/5qkcHnsZ
More verbose example to play with: https://pastebin.com/WRDD7rqc
Discussion on discord: https://discord.com/channels/691052431525675048/1043155921217523752/1043155921217523752
The text was updated successfully, but these errors were encountered: