Replies: 1 comment 1 reply
-
Hi looking at your code what bevy version are you using ? If I would be honest i wouldn't bother with older versions of bevy and I would recommend that you go throught Getting Started from this chapter: https://bevyengine.org/learn/book/getting-started/apps/ |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello there!,
I am fairly new to egui and bevy. I was following some tutorials as well as the documentation and I have come across a problem that I do not know how to resolve.
I was trying to figure out how to store values between frames (in this case, for a slider). I found a youtube tutorial from recently (early this year) in which this is accomplish. However, when I I try to implement what was shown in the video, I get the "the trait bound
EguiContext: Resource
is not satisfied" message. I have seen in another place the same approach, so I was confused as to what was happening. I have digged in the documentation and it seems like EguiContext does not implement the Resouce trait, so, am I missing something or is there a new way (or differente) to accomplish this?This is what I have put together:
`use bevy::prelude::*;
use bevy_egui::{egui, EguiContext};
struct SliderValue {
value: f32,
}
fn setup(mut commands: Commands) {
commands.insert_resource(SliderValue { value: 0.0 });
}
fn my_egui_system(
egui_context: ResMut,
mut slider_value: ResMut,
) {
egui::Window::new("My Window").show(egui_context.ctx(), |ui| {
ui.add(egui::Slider::new(&mut slider_value.value, 0.0..=1.0).text("value"));
});
}
fn main() {
App::build()
.add_plugins(DefaultPlugins)
.add_plugin(bevy_egui::EguiPlugin)
.add_startup_system(setup.system())
.add_system(my_egui_system.system())
.run();
}`
Code from the video that I have used as a guide (video):
`#[derive(Default)]
pub struct EguiState {
spawn_position: Vec2,
}
fn spawn_egui_demo(
mut egui_context: ResMut,
mut commands: Commands,
assets: Res,
mut egui_state: Local,
) {
egui::Window::new("Dev Tools").show(egui_context.ctx_mut(), |ui|{
ui.label("Spawn a Pawn");
ui.horizontal(|ui|{
ui.add(egui::DragValue::new(&mut egui_state.spawn_position.x)
.speed(1.0)
.clamp_range(-5.0..=5.0),
);
ui.add(egui::DragValue::new(&mut egui_state.spawn_position.y)
.speed(1.0)
.clamp_range(-5.0..=5.0),
);
if ui.button("Spawn").clicked(){
info!("{:?}", egui_state.spawn_position);
span_pawn(
&mut commands,
&assets,
egui_state.spawn_position * TILE_SIZE
);
}
});
});
}`
Beta Was this translation helpful? Give feedback.
All reactions