Skip to content

Entity cloning fails for sprites due to warning about duplicate synchronization #18795

Closed
@alice-i-cecile

Description

@alice-i-cecile

Bevy version

0.16-rc.3

What you did

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .add_observer(on_click)
        .run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.spawn(Camera2d);

    commands.spawn(Sprite::from_image(
        asset_server.load("projectiles/fireball.png"),
    ));
}

fn on_click(_: Trigger<Pointer<Click>>, mut commands: Commands, sprite: Single<Entity, With<Sprite>>) {
    commands.entity(*sprite).clone_and_spawn(); // causes error
}

What went wrong

thread 'main' panicked at ...\bevy-50d7e162b728c6c6\73f0332\crates\bevy_render\src\sync_world.rs:220:33:
Attempting to synchronize an entity that has already been synchronized!

Additional information

Bug report stolen from @TheLeafyGreen on Discord; I made this so we can track it in the milestone!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsA-RenderingDrawing game state to the screenC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions