Repository: bevyengine/bevy
File: crates/bevy_scene/src/lib.rs (Rust)

Code before:

        let scene_entity = app.world_mut().spawn(SceneRoot(scene_handle.clone())).id();
        app.update();

        assert!(app.world().entity(scene_entity).get::<Children>().is_none());

        let mut scene_1 = Scene {
            world: World::new(),
        };
        let root = scene_1.world.spawn_empty().id();
        scene_1.world.spawn((
            Rectangle {
                width: 10.0,
                height: 5.0,
            },
            FinishLine,
            ChildOf(root),
        ));
        scene_1.world.spawn((Circle { radius: 7.0 }, ChildOf(root)));

        app.world_mut()
            .resource_mut::<Assets<Scene>>()
            .insert(&scene_handle, scene_1);

        app.update();
        app.update();
        app.update();
        app.update();

        let child_root = app
            .world()
            .entity(scene_entity)
            .get::<Children>()
            .and_then(|children| children.first().cloned())
            .expect("There should be exactly one child on the scene root");
        let children = app
            .world()
            .entity(child_root)
            .get::<Children>()
            .expect("The child of the scene root should itself have 2 children");
        assert_eq!(children.len(), 2);

        let finish_line = app.world().entity(children[0]);
        assert_eq!(finish_line.archetype().component_count(), 3);
        let (rectangle, _, child_of) =
            finish_line.components::<(&Rectangle, &FinishLine, &ChildOf)>();
        assert_eq!(
            rectangle,
            &Rectangle {
                width: 10.0,
                height: 5.0,

Review comment (suggestion):
```suggestion
        // TODO: multiple updates to avoid debounced asset events. See comment on SceneSpawner::debounced_scene_asset_events
        app.update();
```

Code after:
        app.update();

        assert!(app.world().entity(scene_entity).get::<Children>().is_none());

        let mut scene_1 = Scene {
            world: World::new(),
        };
        let root = scene_1.world.spawn_empty().id();
        scene_1.world.spawn((
            Rectangle {
                width: 10.0,
                height: 5.0,
            },
            FinishLine,
            ChildOf(root),
        ));
        scene_1.world.spawn((Circle { radius: 7.0 }, ChildOf(root)));

        app.world_mut()
            .resource_mut::<Assets<Scene>>()
            .insert(&scene_handle, scene_1)
            .unwrap();

        app.update();
        // TODO: multiple updates to avoid debounced asset events. See comment on SceneSpawner::debounced_scene_asset_events
        app.update();
        app.update();
        app.update();

        let child_root = app
            .world()
            .entity(scene_entity)
            .get::<Children>()
            .and_then(|children| children.first().cloned())
            .expect("There should be exactly one child on the scene root");
        let children = app
            .world()
            .entity(child_root)
            .get::<Children>()
            .expect("The child of the scene root should itself have 2 children");
        assert_eq!(children.len(), 2);

        let finish_line = app.world().entity(children[0]);
        assert_eq!(finish_line.archetype().component_count(), 3);
        let (rectangle, _, child_of) =
            finish_line.components::<(&Rectangle, &FinishLine, &ChildOf)>();
        assert_eq!(
            rectangle,
            &Rectangle {
                width: 10.0,
                height: 5.0,