Skip to content

.insert_children/.insert_related inserting first element last #19092

Closed
@databasedav

Description

@databasedav

Bevy version

0.16.0

What you did

repro:

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(MinimalPlugins)
        .add_systems(
            Startup,
            (
                |world: &mut World| {
                    let child = |i: usize| {
                        world.spawn(Name::new(i.to_string())).id()
                    };
                    let children = (0..3).map(child).collect::<Vec<_>>();
                    let mut parent = world.spawn_empty();
                    parent.insert_children(0, &children);
                    // for child in children {
                    //     parent.add_child(child);
                    // }
                    let children = parent.get::<Children>().unwrap().into_iter().copied().collect::<Vec<_>>();
                    for child in children {
                        println!("{:?}", world.entity(child).get::<Name>().unwrap());
                    }
                },
            ),
        )
        .run();
}

outputs

"1"
"2"
"0"

but should output this

"0"
"1"
"2"

which it does when using the commented out .add_child for loop

works fine in 0.15

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesP-RegressionFunctionality that used to work but no longer does. Add a test for this!S-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions