#How to remove a component instantly after inserting

2 messages · Page 1 of 1 (latest)

coarse ravine
#

TL;DR: how do you instantly remove a component on insert?

fn on_add(trigger: Trigger<OnInsert, MyComponent>, mut commands: Commands) {
    commands.entity(trigger.target()).despawn();
}

I've also got a weird one...so I'm using bevy_skein, but well, I'm gonna be animating some models in a bit freakin gltf that I'm importing. the way I'm trying to do this is essentially

fn on_add_blender_timebank(
    trigger: Trigger<OnInsert, BlenderTimebank>,
    mut commands: Commands,
    transforms: Query<&Transform>,
    blender_timebanks: Query<&BlenderTimebank>,
) {
    // we are going to take this thing,
    // remove it from the scene entirely,
    // and then construct it ourselves.
    let transform = transforms.get(trigger.target()).unwrap();
    let BlenderTimebank { milliseconds } = blender_timebanks.get(trigger.target()).unwrap();

    commands.entity(trigger.target()).despawn();
    commands.spawn((
        TimeBank {
            milliseconds: *milliseconds,
        },
        *transform,
    ));
}

but this panics with the error

thread 'main' panicked at /Users/dsgallups/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bevy_scene-0.16.0/src/scene.rs:158:40:
The entity with ID 100v1 does not exist (index has been reused or was never spawned)

is there any decent way to despawn an entity right after it's all settled in the tables?

Note that it is not possible at this time to play animations when using bevy_skein, necessitating this change
I could do some real hacky stuff, inserting two parents onto the inserted type, but I'd rather just remove it entirely

#

ehh