#spawning a entity at mouse click position

9 messages · Page 1 of 1 (latest)

rugged orchid
#

im pretty new to rust and bevy but i cant seem to figure out why the function isnt getting called ```rs

fn build_sys(mut commands: Commands, asset: Res<AssetServer>, selection: Query<(Entity, &PickSelection, &Transform)>,
mouse_input: Res<Input<MouseButton>>,) {

if mouse_input.just_pressed(MouseButton::Left) {
   for (entity,selection,transform) in &selection {
    if selection.is_selected {
        spawn_brick(&mut commands,&asset, transform.translation);
        println!("spawned brick");
    }
}

}

fn spawn_brick(commands: &mut Commands, assets: &AssetServer , position: Vec3) -> Entity {
let brick = assets.load("Models/brick.glb#Scene0");
commands
.spawn(SpatialBundle::from_transform(Transform::from_translation(position)))
.insert(Name::new("Brick"))
.with_children(|commands| {
commands.spawn(SceneBundle{
scene: brick.clone(),
transform: Transform::from_xyz(0.0, 0.0, 0.0),
..Default::default()
});

    })
    .id()
}

}```

median pawn
#

You never get to the println?

rugged orchid
#

nope

median pawn
#

where is system inserted into app?

#

like show that add systems method call

rugged orchid
#

i accidentally set it to startup, it works now ferris_sob

#

i didnt evevn realise

#

thank you