Replies: 1 comment
-
|
How are you adding Let me suggest two alternatives
impl FromWorld for WinSize {
fn from_world(world: &mut World) -> Self {
// impl
}
}Then you need to add the resource to the app as follow:
To simplify the task, you can define a #[derive(SystemParam)]
struct WinSize<'w, 's> {
windows: Query<'w, 's, &Window, With<PrimaryWindow>>,
}
impl<'w, 's> WinSize<'w, 's> {
fn size(&self) -> (u32, u32) {
let resolution = self.windows.get_single().unwrap().resolution;
(resolution.width, resolution.height)
}
}Now if you want to query for window size in a system you do fn win_size_system(win_size: WinSize) {
let size = win_size.size();
println!("{size:?}");
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi All,
I have a
setupsystem that adds a resource containing the primary window's width and height so that I don't need to query for it every time. In other words, I want my future systems to haveRes<WinSize>rather thanQuery<&Window, With<PrimaryWindow>>in their function definition.However, my
spawn_playersystem runs aftersetupand panics because theRes<WinSizehas not yet been added as an available resource. The ordering of system execution is correct, however, the commands have not yet been executed by the timespawn_playerexecutes.I found this useful discussion (#3174) regarding the same issue, however it's not for Bevy 0.10. I noticed that Bevy 0.10's migration notes says the following:
I'm new to the Bevy ecosystem so I've been having a hard time finding examples of
system setsand using theapply_system_buffersfunction. How could I easily ensure a resource that is injected by one system is available by a later system?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions