-
Notifications
You must be signed in to change notification settings - Fork 6
Description
I am developing an RTS game using Bevy with the Rive plugin for handling animations. I've encountered a problem concerning the selection and deselection of a building in the game. The selection logic (triggered by the S key) and building animation (triggered by the B key) are implemented. The issue arises in the way these interactions are handled across different layers: the selection logic is implemented in a separate layer from the main logic layer.
The building is expected to be selected when I press S and deselected when I press it again. However, the building remains marked as selected until I press the B key for the building animation at least once. This issue with the S and B logic in separate layers is just an isolated example within my project.
Expected Behavior:
Pressing S in the selection layer should select the building, and pressing it again should deselect it, regardless of the state of the building animation in the main layer.
Actual Behavior:
The building remains selected until I activate the building animation with the B key at least once, even after pressing S to deselect.
Code for reproduction:
use bevy::{prelude::*, render::render_resource::Extent3d, window};
use rive_bevy::{RivePlugin, SceneTarget, SpriteEntity, StateMachine, RiveStateMachine};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(RivePlugin)
.add_systems(Startup, setup_animation)
.add_systems(Update, (window::close_on_esc, update))
.run()
}
fn setup_animation(
mut commands: Commands,
mut images: ResMut<Assets<Image>>,
asset_server: Res<AssetServer>,
) {
let mut image = Image::default();
image.resize(Extent3d {
width: 128,
height: 128,
..default()
});
let image_handle = images.add(image.clone());
commands.spawn(Camera2dBundle { ..default() });
let sprite_entity = commands
.spawn(SpriteBundle {
texture: image_handle.clone(),
transform: Transform::from_scale(Vec3::splat(1.0)),
..default()
})
.id();
let state_machine = StateMachine {
riv: asset_server.load("genesis.riv"),
..default()
};
commands.spawn(state_machine).insert(SceneTarget {
image: image_handle,
sprite: SpriteEntity {
entity: Some(sprite_entity),
},
..default()
});
}
fn update(input: Res<Input<KeyCode>>, query: Query<&mut RiveStateMachine>) {
let state_machine = query.single();
if input.just_pressed(KeyCode::C) {
state_machine.get_number("progress").unwrap().set(100.0);
}
if input.just_pressed(KeyCode::S) {
let mut selected = state_machine.get_bool("selected").unwrap();
selected.set(!selected.get());
}
if input.just_pressed(KeyCode::B) {
let mut build = state_machine.get_bool("build").unwrap();
build.set(!build.get());
}
}Important: You need to press C first after application startup, to show the "building".
Attachments:
genesis.rev.txt
genesis.riv.txt
I had to rename with .txt extension to attach to issue.
Dependencies of Cargo.toml:
[dependencies]
bevy = "0.12.0"
rive-bevy = { git = "https://github.com/rive-app/rive-bevy" }