pub struct App { /* private fields */ }Expand description
App is the primary API for writing user applications. It automates the setup of a
standard lifecycle and provides interface glue for plugins.
A single App can contain multiple SubApp instances, but App methods only affect
the “main” one. To access a particular SubApp, use get_sub_app
or get_sub_app_mut.
§Examples
Here is a simple “Hello World” Bevy app:
fn main() {
App::new()
.add_systems(Update, hello_world_system)
.run();
}
fn hello_world_system() {
println!("hello world");
}Implementations§
Source§impl App
impl App
Sourcepub fn new() -> App
pub fn new() -> App
Creates a new App with some default structure to enable core engine features.
This is the preferred constructor for most use cases.
Examples found in repository?
More examples
- examples/reflection/reflection_types.rs
- examples/ui/ui_drag_and_drop.rs
- examples/input/mouse_grab.rs
- examples/input/touch_input.rs
- examples/input/gamepad_input.rs
- examples/input/gamepad_rumble.rs
- examples/input/touch_input_events.rs
- examples/input/keyboard_input.rs
- examples/input/keyboard_modifiers.rs
- examples/app/drag_and_drop.rs
- examples/input/mouse_input_events.rs
- examples/input/keyboard_input_events.rs
- examples/picking/dragdrop_picking.rs
- examples/asset/embedded_asset.rs
- examples/reflection/serialization.rs
- examples/2d/mesh2d_repeated_texture.rs
- examples/input/mouse_input.rs
- examples/input/gamepad_input_events.rs
- examples/2d/sprite_tile.rs
- examples/ui/ui_texture_slice_flip_and_tile.rs
- examples/ui/ui_texture_atlas_slice.rs
- examples/ui/ui_texture_slice.rs
- examples/3d/parenting.rs
- examples/2d/move_sprite.rs
- examples/shader/shader_material.rs
- examples/shader/shader_material_glsl.rs
- examples/shader_advanced/custom_vertex_attribute.rs
- examples/3d/animated_material.rs
- examples/ecs/system_param.rs
- tests/3d/no_prepass.rs
- examples/ui/z_index.rs
- examples/2d/bloom_2d.rs
- examples/gltf/load_gltf_extras.rs
- examples/app/thread_pool_resources.rs
- examples/ui/virtual_keyboard.rs
- examples/window/screenshot.rs
- examples/asset/web_asset.rs
- examples/shader/shader_material_2d.rs
- examples/shader/storage_buffer.rs
- examples/shader/fallback_image.rs
- examples/ui/tab_navigation.rs
- examples/2d/sprite_sheet.rs
- examples/reflection/generic_reflection.rs
- examples/3d/spherical_area_lights.rs
- examples/app/log_layers.rs
- examples/gltf/update_gltf_scene.rs
- examples/gltf/load_gltf.rs
- examples/audio/audio_control.rs
- examples/animation/animated_transform.rs
- examples/shader/shader_material_wesl.rs
- examples/ui/font_atlas_debug.rs
- examples/gltf/gltf_skinned_mesh.rs
- examples/diagnostics/enabling_disabling_diagnostic.rs
- examples/app/no_renderer.rs
- examples/remote/server.rs
- examples/asset/asset_settings.rs
- examples/app/return_after_run.rs
- examples/window/scale_factor_override.rs
- examples/app/logs.rs
- examples/asset/extra_source.rs
- examples/app/plugin_group.rs
- examples/ui/window_fallthrough.rs
- examples/window/transparent_window.rs
- examples/app/headless.rs
- examples/dev_tools/fps_overlay.rs
- examples/ecs/system_stepping.rs
Sourcepub fn empty() -> App
pub fn empty() -> App
Creates a new empty App with minimal default configuration.
Use this constructor if you want to customize scheduling, exit handling, cleanup, etc.
Sourcepub fn update(&mut self)
pub fn update(&mut self)
Runs the default schedules of all sub-apps (starting with the “main” app) once.
Examples found in repository?
7fn main() {
8 let mut app = App::new();
9
10 app
11 // to display log messages from Stepping resource
12 .add_plugins(LogPlugin::default())
13 .add_systems(
14 Update,
15 (
16 update_system_one,
17 // establish a dependency here to simplify descriptions below
18 update_system_two.after(update_system_one),
19 update_system_three.after(update_system_two),
20 update_system_four,
21 ),
22 )
23 .add_systems(PreUpdate, pre_update_system);
24
25 // For the simplicity of this example, we directly modify the `Stepping`
26 // resource here and run the systems with `App::update()`. Each call to
27 // `App::update()` is the equivalent of a single frame render when using
28 // `App::run()`.
29 //
30 // In a real-world situation, the `Stepping` resource would be modified by
31 // a system based on input from the user. A full demonstration of this can
32 // be found in the breakout example.
33 println!(
34 r#"
35 Actions: call app.update()
36 Result: All systems run normally"#
37 );
38 app.update();
39
40 println!(
41 r#"
42 Actions: Add the Stepping resource then call app.update()
43 Result: All systems run normally. Stepping has no effect unless explicitly
44 configured for a Schedule, and Stepping has been enabled."#
45 );
46 app.insert_resource(Stepping::new());
47 app.update();
48
49 println!(
50 r#"
51 Actions: Add the Update Schedule to Stepping; enable Stepping; call
52 app.update()
53 Result: Only the systems in PreUpdate run. When Stepping is enabled,
54 systems in the configured schedules will not run unless:
55 * Stepping::step_frame() is called
56 * Stepping::continue_frame() is called
57 * System has been configured to always run"#
58 );
59 let mut stepping = app.world_mut().resource_mut::<Stepping>();
60 stepping.add_schedule(Update).enable();
61 app.update();
62
63 println!(
64 r#"
65 Actions: call Stepping.step_frame(); call app.update()
66 Result: The PreUpdate systems run, and one Update system will run. In
67 Stepping, step means run the next system across all the schedules
68 that have been added to the Stepping resource."#
69 );
70 let mut stepping = app.world_mut().resource_mut::<Stepping>();
71 stepping.step_frame();
72 app.update();
73
74 println!(
75 r#"
76 Actions: call app.update()
77 Result: Only the PreUpdate systems run. The previous call to
78 Stepping::step_frame() only applies for the next call to
79 app.update()/the next frame rendered.
80 "#
81 );
82 app.update();
83
84 println!(
85 r#"
86 Actions: call Stepping::continue_frame(); call app.update()
87 Result: PreUpdate system will run, and all remaining Update systems will
88 run. Stepping::continue_frame() tells stepping to run all systems
89 starting after the last run system until it hits the end of the
90 frame, or it encounters a system with a breakpoint set. In this
91 case, we previously performed a step, running one system in Update.
92 This continue will cause all remaining systems in Update to run."#
93 );
94 let mut stepping = app.world_mut().resource_mut::<Stepping>();
95 stepping.continue_frame();
96 app.update();
97
98 println!(
99 r#"
100 Actions: call Stepping::step_frame() & app.update() four times in a row
101 Result: PreUpdate system runs every time we call app.update(), along with
102 one system from the Update schedule each time. This shows what
103 execution would look like to step through an entire frame of
104 systems."#
105 );
106 for _ in 0..4 {
107 let mut stepping = app.world_mut().resource_mut::<Stepping>();
108 stepping.step_frame();
109 app.update();
110 }
111
112 println!(
113 r#"
114 Actions: Stepping::always_run(Update, update_system_two); step through all
115 systems
116 Result: PreUpdate system and update_system_two() will run every time we
117 call app.update(). We'll also only need to step three times to
118 execute all systems in the frame. Stepping::always_run() allows
119 us to granularly allow systems to run when stepping is enabled."#
120 );
121 let mut stepping = app.world_mut().resource_mut::<Stepping>();
122 stepping.always_run(Update, update_system_two);
123 for _ in 0..3 {
124 let mut stepping = app.world_mut().resource_mut::<Stepping>();
125 stepping.step_frame();
126 app.update();
127 }
128
129 println!(
130 r#"
131 Actions: Stepping::never_run(Update, update_system_two); continue through
132 all systems
133 Result: All systems except update_system_two() will execute.
134 Stepping::never_run() allows us to disable systems while Stepping
135 is enabled."#
136 );
137 let mut stepping = app.world_mut().resource_mut::<Stepping>();
138 stepping.never_run(Update, update_system_two);
139 stepping.continue_frame();
140 app.update();
141
142 println!(
143 r#"
144 Actions: Stepping::set_breakpoint(Update, update_system_two); continue,
145 step, continue
146 Result: During the first continue, pre_update_system() and
147 update_system_one() will run. update_system_four() may also run
148 as it has no dependency on update_system_two() or
149 update_system_three(). Nether update_system_two() nor
150 update_system_three() will run in the first app.update() call as
151 they form a chained dependency on update_system_one() and run
152 in order of one, two, three. Stepping stops system execution in
153 the Update schedule when it encounters the breakpoint for
154 update_system_two().
155 During the step we run update_system_two() along with the
156 pre_update_system().
157 During the final continue pre_update_system() and
158 update_system_three() run."#
159 );
160 let mut stepping = app.world_mut().resource_mut::<Stepping>();
161 stepping.set_breakpoint(Update, update_system_two);
162 stepping.continue_frame();
163 app.update();
164 let mut stepping = app.world_mut().resource_mut::<Stepping>();
165 stepping.step_frame();
166 app.update();
167 let mut stepping = app.world_mut().resource_mut::<Stepping>();
168 stepping.continue_frame();
169 app.update();
170
171 println!(
172 r#"
173 Actions: Stepping::clear_breakpoint(Update, update_system_two); continue
174 through all systems
175 Result: All systems will run"#
176 );
177 let mut stepping = app.world_mut().resource_mut::<Stepping>();
178 stepping.clear_breakpoint(Update, update_system_two);
179 stepping.continue_frame();
180 app.update();
181
182 println!(
183 r#"
184 Actions: Stepping::disable(); app.update()
185 Result: All systems will run. With Stepping disabled, there's no need to
186 call Stepping::step_frame() or Stepping::continue_frame() to run
187 systems in the Update schedule."#
188 );
189 let mut stepping = app.world_mut().resource_mut::<Stepping>();
190 stepping.disable();
191 app.update();
192}Sourcepub fn run(&mut self) -> AppExit
pub fn run(&mut self) -> AppExit
Runs the App by calling its runner.
This will (re)build the App first. For general usage, see the example on the item
level documentation.
§Caveats
Calls to App::run() will never return on iOS and Web.
Headless apps can generally expect this method to return control to the caller when it completes, but that is not the case for windowed apps. Windowed apps are typically driven by an event loop and some platforms expect the program to terminate when the event loop ends.
By default, Bevy uses the winit crate for window creation.
§Panics
Panics if not all plugins have been built.
Examples found in repository?
More examples
- examples/reflection/reflection_types.rs
- examples/ui/ui_drag_and_drop.rs
- examples/input/mouse_grab.rs
- examples/input/touch_input.rs
- examples/input/gamepad_input.rs
- examples/input/gamepad_rumble.rs
- examples/input/touch_input_events.rs
- examples/input/keyboard_input.rs
- examples/input/keyboard_modifiers.rs
- examples/app/drag_and_drop.rs
- examples/input/mouse_input_events.rs
- examples/input/keyboard_input_events.rs
- examples/picking/dragdrop_picking.rs
- examples/asset/embedded_asset.rs
- examples/reflection/serialization.rs
- examples/2d/mesh2d_repeated_texture.rs
- examples/input/mouse_input.rs
- examples/input/gamepad_input_events.rs
- examples/2d/sprite_tile.rs
- examples/ui/ui_texture_slice_flip_and_tile.rs
- examples/ui/ui_texture_atlas_slice.rs
- examples/ui/ui_texture_slice.rs
- examples/3d/parenting.rs
- examples/2d/move_sprite.rs
- examples/shader/shader_material.rs
- examples/shader/shader_material_glsl.rs
- examples/shader_advanced/custom_vertex_attribute.rs
- examples/3d/animated_material.rs
- examples/ecs/system_param.rs
- tests/3d/no_prepass.rs
- examples/ui/z_index.rs
- examples/2d/bloom_2d.rs
- examples/gltf/load_gltf_extras.rs
- examples/app/thread_pool_resources.rs
- examples/ui/virtual_keyboard.rs
- examples/window/screenshot.rs
- examples/asset/web_asset.rs
- examples/shader/shader_material_2d.rs
- examples/shader/storage_buffer.rs
- examples/shader/fallback_image.rs
- examples/ui/tab_navigation.rs
- examples/2d/sprite_sheet.rs
- examples/reflection/generic_reflection.rs
- examples/3d/spherical_area_lights.rs
- examples/app/log_layers.rs
- examples/gltf/update_gltf_scene.rs
- examples/gltf/load_gltf.rs
- examples/audio/audio_control.rs
- examples/animation/animated_transform.rs
- examples/shader/shader_material_wesl.rs
- examples/ui/font_atlas_debug.rs
- examples/gltf/gltf_skinned_mesh.rs
- examples/diagnostics/enabling_disabling_diagnostic.rs
- examples/app/no_renderer.rs
- examples/remote/server.rs
- examples/asset/asset_settings.rs
- examples/app/return_after_run.rs
- examples/window/scale_factor_override.rs
- examples/app/logs.rs
- examples/asset/extra_source.rs
- examples/app/plugin_group.rs
- examples/ui/window_fallthrough.rs
- examples/window/transparent_window.rs
- examples/app/headless.rs
- examples/dev_tools/fps_overlay.rs
Sourcepub fn set_runner(
&mut self,
f: impl FnOnce(App) -> AppExit + 'static,
) -> &mut App
pub fn set_runner( &mut self, f: impl FnOnce(App) -> AppExit + 'static, ) -> &mut App
Sets the function that will be called when the app is run.
The runner function f is called only once by App::run. If the
presence of a main loop in the app is desired, it is the responsibility of the runner
function to provide it.
The runner function is usually not set manually, but by Bevy integrated plugins
(e.g. WinitPlugin).
§Examples
fn my_runner(mut app: App) -> AppExit {
loop {
println!("In main loop");
app.update();
if let Some(exit) = app.should_exit() {
return exit;
}
}
}
App::new()
.set_runner(my_runner);Sourcepub fn plugins_state(&mut self) -> PluginsState
pub fn plugins_state(&mut self) -> PluginsState
Returns the state of all plugins. This is usually called by the event loop, but can be
useful for situations where you want to use App::update.
Sourcepub fn finish(&mut self)
pub fn finish(&mut self)
Runs Plugin::finish for each plugin. This is usually called by the event loop once all
plugins are ready, but can be useful for situations where you want to use App::update.
Sourcepub fn cleanup(&mut self)
pub fn cleanup(&mut self)
Runs Plugin::cleanup for each plugin. This is usually called by the event loop after
App::finish, but can be useful for situations where you want to use App::update.
Sourcepub fn add_systems<M>(
&mut self,
schedule: impl ScheduleLabel,
systems: impl IntoScheduleConfigs<Box<dyn System<In = (), Out = ()>>, M>,
) -> &mut App
pub fn add_systems<M>( &mut self, schedule: impl ScheduleLabel, systems: impl IntoScheduleConfigs<Box<dyn System<In = (), Out = ()>>, M>, ) -> &mut App
Adds one or more systems to the given schedule in this app’s Schedules.
§Examples
app.add_systems(Update, (system_a, system_b, system_c));
app.add_systems(Update, (system_a, system_b).run_if(should_run));Examples found in repository?
40 fn build(&self, app: &mut App) {
41 app.add_systems(Update, print_hello_system);
42 }
43}
44
45fn print_hello_system() {
46 info!("hello");
47}
48
49struct PrintWorldPlugin;
50
51impl Plugin for PrintWorldPlugin {
52 fn build(&self, app: &mut App) {
53 app.add_systems(Update, print_world_system);
54 }More examples
- examples/ui/ui_drag_and_drop.rs
- examples/input/mouse_grab.rs
- examples/input/touch_input.rs
- examples/input/gamepad_input.rs
- examples/input/gamepad_rumble.rs
- examples/input/touch_input_events.rs
- examples/input/keyboard_input.rs
- examples/input/keyboard_modifiers.rs
- examples/app/drag_and_drop.rs
- examples/input/mouse_input_events.rs
- examples/input/keyboard_input_events.rs
- examples/picking/dragdrop_picking.rs
- examples/asset/embedded_asset.rs
- examples/reflection/serialization.rs
- examples/2d/mesh2d_repeated_texture.rs
- examples/input/mouse_input.rs
- examples/input/gamepad_input_events.rs
- examples/2d/sprite_tile.rs
- examples/ui/ui_texture_slice_flip_and_tile.rs
- examples/ui/ui_texture_atlas_slice.rs
- examples/ui/ui_texture_slice.rs
- examples/3d/parenting.rs
- examples/2d/move_sprite.rs
- examples/shader/shader_material.rs
- examples/shader/shader_material_glsl.rs
- examples/shader_advanced/custom_vertex_attribute.rs
- examples/3d/animated_material.rs
- examples/ecs/system_param.rs
- examples/ui/z_index.rs
- examples/2d/bloom_2d.rs
- examples/gltf/load_gltf_extras.rs
- examples/ui/virtual_keyboard.rs
- examples/window/screenshot.rs
- examples/asset/web_asset.rs
- examples/shader/shader_material_2d.rs
- examples/shader/storage_buffer.rs
- examples/shader/fallback_image.rs
- examples/ui/tab_navigation.rs
- examples/2d/sprite_sheet.rs
- examples/reflection/generic_reflection.rs
- examples/3d/spherical_area_lights.rs
- examples/app/log_layers.rs
- examples/gltf/update_gltf_scene.rs
- examples/gltf/load_gltf.rs
- examples/audio/audio_control.rs
- examples/animation/animated_transform.rs
- examples/shader/shader_material_wesl.rs
- examples/ui/font_atlas_debug.rs
- examples/gltf/gltf_skinned_mesh.rs
- examples/diagnostics/enabling_disabling_diagnostic.rs
- examples/remote/server.rs
- examples/asset/asset_settings.rs
- examples/app/return_after_run.rs
- examples/window/scale_factor_override.rs
- examples/app/logs.rs
- examples/asset/extra_source.rs
- examples/ui/window_fallthrough.rs
- examples/window/transparent_window.rs
- examples/app/headless.rs
- examples/dev_tools/fps_overlay.rs
- examples/ecs/system_stepping.rs
Sourcepub fn remove_systems_in_set<M>(
&mut self,
schedule: impl ScheduleLabel,
set: impl IntoSystemSet<M>,
policy: ScheduleCleanupPolicy,
) -> Result<usize, ScheduleError>
pub fn remove_systems_in_set<M>( &mut self, schedule: impl ScheduleLabel, set: impl IntoSystemSet<M>, policy: ScheduleCleanupPolicy, ) -> Result<usize, ScheduleError>
Removes all systems in a SystemSet. This will cause the schedule to be rebuilt when
the schedule is run again and can be slow. A ScheduleError is returned if the schedule needs to be
Schedule::initialize’d or the set is not found.
Note that this can remove all systems of a type if you pass the system to this function as systems implicitly create a set based on the system type.
§Example
// add the system
app.add_systems(Update, system_a);
// remove the system
app.remove_systems_in_set(Update, system_a, ScheduleCleanupPolicy::RemoveSystemsOnly);Sourcepub fn register_system<I, O, M>(
&mut self,
system: impl IntoSystem<I, O, M> + 'static,
) -> SystemId<I, O>where
I: SystemInput + 'static,
O: 'static,
pub fn register_system<I, O, M>(
&mut self,
system: impl IntoSystem<I, O, M> + 'static,
) -> SystemId<I, O>where
I: SystemInput + 'static,
O: 'static,
Registers a system and returns a SystemId so it can later be called by World::run_system.
It’s possible to register the same systems more than once, they’ll be stored separately.
This is different from adding systems to a Schedule with App::add_systems,
because the SystemId that is returned can be used anywhere in the World to run the associated system.
This allows for running systems in a push-based fashion.
Using a Schedule is still preferred for most cases
due to its better performance and ability to run non-conflicting systems simultaneously.
Sourcepub fn configure_sets<M>(
&mut self,
schedule: impl ScheduleLabel,
sets: impl IntoScheduleConfigs<Interned<dyn SystemSet>, M>,
) -> &mut App
pub fn configure_sets<M>( &mut self, schedule: impl ScheduleLabel, sets: impl IntoScheduleConfigs<Interned<dyn SystemSet>, M>, ) -> &mut App
Configures a collection of system sets in the provided schedule, adding any sets that do not exist.
Sourcepub fn add_message<M>(&mut self) -> &mut Appwhere
M: Message,
pub fn add_message<M>(&mut self) -> &mut Appwhere
M: Message,
Initializes Message handling for T by inserting a message queue resource (Messages::<T>)
and scheduling an message_update_system in First.
See Messages for information on how to define messages.
§Examples
app.add_message::<MyMessage>();Sourcepub fn insert_resource<R>(&mut self, resource: R) -> &mut Appwhere
R: Resource,
pub fn insert_resource<R>(&mut self, resource: R) -> &mut Appwhere
R: Resource,
Inserts the Resource into the app, overwriting any existing resource of the same type.
There is also an init_resource for resources that have
Default or FromWorld implementations.
§Examples
#[derive(Resource)]
struct MyCounter {
counter: usize,
}
App::new()
.insert_resource(MyCounter { counter: 0 });Examples found in repository?
More examples
Sourcepub fn init_resource<R>(&mut self) -> &mut App
pub fn init_resource<R>(&mut self) -> &mut App
Inserts the Resource, initialized with its default value, into the app,
if there is no existing instance of R.
R must implement FromWorld.
If R implements Default, FromWorld will be automatically implemented and
initialize the Resource with Default::default.
§Examples
#[derive(Resource)]
struct MyCounter {
counter: usize,
}
impl Default for MyCounter {
fn default() -> MyCounter {
MyCounter {
counter: 100
}
}
}
App::new()
.init_resource::<MyCounter>();Sourcepub fn insert_non_send_resource<R>(&mut self, resource: R) -> &mut Appwhere
R: 'static,
pub fn insert_non_send_resource<R>(&mut self, resource: R) -> &mut Appwhere
R: 'static,
Inserts the !Send resource into the app, overwriting any existing resource
of the same type.
There is also an init_non_send_resource for
resources that implement Default
§Examples
struct MyCounter {
counter: usize,
}
App::new()
.insert_non_send_resource(MyCounter { counter: 0 });Sourcepub fn init_non_send_resource<R>(&mut self) -> &mut Appwhere
R: 'static + FromWorld,
pub fn init_non_send_resource<R>(&mut self) -> &mut Appwhere
R: 'static + FromWorld,
Sourcepub fn is_plugin_added<T>(&self) -> boolwhere
T: Plugin,
pub fn is_plugin_added<T>(&self) -> boolwhere
T: Plugin,
Returns true if the Plugin has already been added.
Sourcepub fn get_added_plugins<T>(&self) -> Vec<&T>where
T: Plugin,
pub fn get_added_plugins<T>(&self) -> Vec<&T>where
T: Plugin,
Returns a vector of references to all plugins of type T that have been added.
This can be used to read the settings of any existing plugins.
This vector will be empty if no plugins of that type have been added.
If multiple copies of the same plugin are added to the App, they will be listed in insertion order in this vector.
let default_sampler = app.get_added_plugins::<ImagePlugin>()[0].default_sampler;Sourcepub fn add_plugins<M>(&mut self, plugins: impl Plugins<M>) -> &mut App
pub fn add_plugins<M>(&mut self, plugins: impl Plugins<M>) -> &mut App
Installs a Plugin collection.
Bevy prioritizes modularity as a core principle. All engine features are implemented as plugins, even the complex ones like rendering.
Plugins can be grouped into a set by using a PluginGroup.
There are built-in PluginGroups that provide core engine functionality.
The PluginGroups available by default are DefaultPlugins and MinimalPlugins.
To customize the plugins in the group (reorder, disable a plugin, add a new plugin
before / after another plugin), call build() on the group,
which will convert it to a PluginGroupBuilder.
You can also specify a group of Plugins by using a tuple over Plugins and
PluginGroups. See Plugins for more details.
§Examples
App::new()
.add_plugins(MinimalPlugins);
App::new()
.add_plugins((MinimalPlugins, LogPlugin));§Panics
Panics if one of the plugins had already been added to the application.
Examples found in repository?
More examples
- examples/ui/ui_drag_and_drop.rs
- examples/input/mouse_grab.rs
- examples/input/touch_input.rs
- examples/input/gamepad_input.rs
- examples/input/gamepad_rumble.rs
- examples/input/touch_input_events.rs
- examples/input/keyboard_input.rs
- examples/input/keyboard_modifiers.rs
- examples/app/drag_and_drop.rs
- examples/input/mouse_input_events.rs
- examples/input/keyboard_input_events.rs
- examples/picking/dragdrop_picking.rs
- examples/asset/embedded_asset.rs
- examples/reflection/serialization.rs
- examples/2d/mesh2d_repeated_texture.rs
- examples/input/mouse_input.rs
- examples/input/gamepad_input_events.rs
- examples/2d/sprite_tile.rs
- examples/ui/ui_texture_slice_flip_and_tile.rs
- examples/ui/ui_texture_atlas_slice.rs
- examples/ui/ui_texture_slice.rs
- examples/3d/parenting.rs
- examples/2d/move_sprite.rs
- examples/shader/shader_material.rs
- examples/shader/shader_material_glsl.rs
- examples/shader_advanced/custom_vertex_attribute.rs
- examples/3d/animated_material.rs
- tests/3d/no_prepass.rs
- examples/ui/z_index.rs
- examples/2d/bloom_2d.rs
- examples/gltf/load_gltf_extras.rs
- examples/app/thread_pool_resources.rs
- examples/ui/virtual_keyboard.rs
- examples/window/screenshot.rs
- examples/asset/web_asset.rs
- examples/shader/shader_material_2d.rs
- examples/shader/storage_buffer.rs
- examples/shader/fallback_image.rs
- examples/ui/tab_navigation.rs
- examples/2d/sprite_sheet.rs
- examples/reflection/generic_reflection.rs
- examples/3d/spherical_area_lights.rs
- examples/app/log_layers.rs
- examples/gltf/update_gltf_scene.rs
- examples/gltf/load_gltf.rs
- examples/audio/audio_control.rs
- examples/animation/animated_transform.rs
- examples/shader/shader_material_wesl.rs
- examples/ui/font_atlas_debug.rs
- examples/gltf/gltf_skinned_mesh.rs
- examples/diagnostics/enabling_disabling_diagnostic.rs
- examples/app/no_renderer.rs
- examples/remote/server.rs
- examples/asset/asset_settings.rs
- examples/app/return_after_run.rs
- examples/window/scale_factor_override.rs
- examples/app/logs.rs
- examples/asset/extra_source.rs
- examples/app/plugin_group.rs
- examples/ui/window_fallthrough.rs
- examples/window/transparent_window.rs
- examples/app/headless.rs
- examples/dev_tools/fps_overlay.rs
- examples/ecs/system_stepping.rs
Sourcepub fn register_type<T>(&mut self) -> &mut Appwhere
T: GetTypeRegistration,
Available on crate feature bevy_reflect only.
pub fn register_type<T>(&mut self) -> &mut Appwhere
T: GetTypeRegistration,
bevy_reflect only.Registers the type T in the AppTypeRegistry resource,
adding reflect data as specified in the Reflect derive:
#[derive(Component, Serialize, Deserialize, Reflect)]
#[reflect(Component, Serialize, Deserialize)] // will register ReflectComponent, ReflectSerialize, ReflectDeserializeSee bevy_reflect::TypeRegistry::register for more information.
Sourcepub fn register_type_data<T, D>(&mut self) -> &mut App
Available on crate feature bevy_reflect only.
pub fn register_type_data<T, D>(&mut self) -> &mut App
bevy_reflect only.Associates type data D with type T in the AppTypeRegistry resource.
Most of the time register_type can be used instead to register a
type you derived Reflect for. However, in cases where you want to
add a piece of type data that was not included in the list of #[reflect(...)] type data in
the derive, or where the type is generic and cannot register e.g. ReflectSerialize
unconditionally without knowing the specific type parameters, this method can be used to
insert additional type data.
§Example
use bevy_app::App;
use bevy_reflect::{ReflectSerialize, ReflectDeserialize};
App::new()
.register_type::<Option<String>>()
.register_type_data::<Option<String>, ReflectSerialize>()
.register_type_data::<Option<String>, ReflectDeserialize>();Sourcepub fn register_function<F, Marker>(&mut self, function: F) -> &mut Appwhere
F: IntoFunction<'static, Marker> + 'static,
Available on crate feature reflect_functions only.
pub fn register_function<F, Marker>(&mut self, function: F) -> &mut Appwhere
F: IntoFunction<'static, Marker> + 'static,
reflect_functions only.Registers the given function into the AppFunctionRegistry resource.
The given function will internally be stored as a DynamicFunction
and mapped according to its name.
Because the function must have a name,
anonymous functions (e.g. |a: i32, b: i32| { a + b }) and closures must instead
be registered using register_function_with_name or converted to a DynamicFunction
and named using DynamicFunction::with_name.
Failure to do so will result in a panic.
Only types that implement IntoFunction may be registered via this method.
See FunctionRegistry::register for more information.
§Panics
Panics if a function has already been registered with the given name or if the function is missing a name (such as when it is an anonymous function).
§Examples
use bevy_app::App;
fn add(a: i32, b: i32) -> i32 {
a + b
}
App::new().register_function(add);Functions cannot be registered more than once.
use bevy_app::App;
fn add(a: i32, b: i32) -> i32 {
a + b
}
App::new()
.register_function(add)
// Panic! A function has already been registered with the name "my_function"
.register_function(add);Anonymous functions and closures should be registered using register_function_with_name or given a name using DynamicFunction::with_name.
use bevy_app::App;
// Panic! Anonymous functions cannot be registered using `register_function`
App::new().register_function(|a: i32, b: i32| a + b);Sourcepub fn register_function_with_name<F, Marker>(
&mut self,
name: impl Into<Cow<'static, str>>,
function: F,
) -> &mut Appwhere
F: IntoFunction<'static, Marker> + 'static,
Available on crate feature reflect_functions only.
pub fn register_function_with_name<F, Marker>(
&mut self,
name: impl Into<Cow<'static, str>>,
function: F,
) -> &mut Appwhere
F: IntoFunction<'static, Marker> + 'static,
reflect_functions only.Registers the given function or closure into the AppFunctionRegistry resource using the given name.
To avoid conflicts, it’s recommended to use a unique name for the function. This can be achieved by “namespacing” the function with a unique identifier, such as the name of your crate.
For example, to register a function, add, from a crate, my_crate,
you could use the name, "my_crate::add".
Another approach could be to use the type name of the function, however, it should be noted that anonymous functions do not have unique type names.
For named functions (e.g. fn add(a: i32, b: i32) -> i32 { a + b }) where a custom name is not needed,
it’s recommended to use register_function instead as the generated name is guaranteed to be unique.
Only types that implement IntoFunction may be registered via this method.
See FunctionRegistry::register_with_name for more information.
§Panics
Panics if a function has already been registered with the given name.
§Examples
use bevy_app::App;
fn mul(a: i32, b: i32) -> i32 {
a * b
}
let div = |a: i32, b: i32| a / b;
App::new()
// Registering an anonymous function with a unique name
.register_function_with_name("my_crate::add", |a: i32, b: i32| {
a + b
})
// Registering an existing function with its type name
.register_function_with_name(std::any::type_name_of_val(&mul), mul)
// Registering an existing function with a custom name
.register_function_with_name("my_crate::mul", mul)
// Be careful not to register anonymous functions with their type name.
// This code works but registers the function with a non-unique name like `foo::bar::{{closure}}`
.register_function_with_name(std::any::type_name_of_val(&div), div);Names must be unique.
use bevy_app::App;
fn one() {}
fn two() {}
App::new()
.register_function_with_name("my_function", one)
// Panic! A function has already been registered with the name "my_function"
.register_function_with_name("my_function", two);Sourcepub fn register_required_components<T, R>(&mut self) -> &mut App
pub fn register_required_components<T, R>(&mut self) -> &mut App
Registers the given component R as a required component for T.
When T is added to an entity, R and its own required components will also be added
if R was not already provided. The Default constructor will be used for the creation of R.
If a custom constructor is desired, use App::register_required_components_with instead.
For the non-panicking version, see App::try_register_required_components.
Note that requirements must currently be registered before T is inserted into the world
for the first time. Commonly, this is done in plugins. This limitation may be fixed in the future.
§Panics
Panics if R is already a directly required component for T, or if T has ever been added
on an entity before the registration.
Indirect requirements through other components are allowed. In those cases, any existing requirements will only be overwritten if the new requirement is more specific.
§Example
#[derive(Component)]
struct A;
#[derive(Component, Default, PartialEq, Eq, Debug)]
struct B(usize);
#[derive(Component, Default, PartialEq, Eq, Debug)]
struct C(u32);
// Register B as required by A and C as required by B.
app.register_required_components::<A, B>();
app.register_required_components::<B, C>();
fn setup(mut commands: Commands) {
// This will implicitly also insert B and C with their Default constructors.
commands.spawn(A);
}
fn validate(query: Option<Single<(&A, &B, &C)>>) {
let (a, b, c) = query.unwrap().into_inner();
assert_eq!(b, &B(0));
assert_eq!(c, &C(0));
}Sourcepub fn register_required_components_with<T, R>(
&mut self,
constructor: fn() -> R,
) -> &mut App
pub fn register_required_components_with<T, R>( &mut self, constructor: fn() -> R, ) -> &mut App
Registers the given component R as a required component for T.
When T is added to an entity, R and its own required components will also be added
if R was not already provided. The given constructor will be used for the creation of R.
If a Default constructor is desired, use App::register_required_components instead.
For the non-panicking version, see App::try_register_required_components_with.
Note that requirements must currently be registered before T is inserted into the world
for the first time. Commonly, this is done in plugins. This limitation may be fixed in the future.
§Panics
Panics if R is already a directly required component for T, or if T has ever been added
on an entity before the registration.
Indirect requirements through other components are allowed. In those cases, any existing requirements will only be overwritten if the new requirement is more specific.
§Example
#[derive(Component)]
struct A;
#[derive(Component, Default, PartialEq, Eq, Debug)]
struct B(usize);
#[derive(Component, Default, PartialEq, Eq, Debug)]
struct C(u32);
// Register B and C as required by A and C as required by B.
// A requiring C directly will overwrite the indirect requirement through B.
app.register_required_components::<A, B>();
app.register_required_components_with::<B, C>(|| C(1));
app.register_required_components_with::<A, C>(|| C(2));
fn setup(mut commands: Commands) {
// This will implicitly also insert B with its Default constructor and C
// with the custom constructor defined by A.
commands.spawn(A);
}
fn validate(query: Option<Single<(&A, &B, &C)>>) {
let (a, b, c) = query.unwrap().into_inner();
assert_eq!(b, &B(0));
assert_eq!(c, &C(2));
}Sourcepub fn try_register_required_components<T, R>(
&mut self,
) -> Result<(), RequiredComponentsError>
pub fn try_register_required_components<T, R>( &mut self, ) -> Result<(), RequiredComponentsError>
Tries to register the given component R as a required component for T.
When T is added to an entity, R and its own required components will also be added
if R was not already provided. The Default constructor will be used for the creation of R.
If a custom constructor is desired, use App::register_required_components_with instead.
For the panicking version, see App::register_required_components.
Note that requirements must currently be registered before T is inserted into the world
for the first time. Commonly, this is done in plugins. This limitation may be fixed in the future.
§Errors
Returns a RequiredComponentsError if R is already a directly required component for T, or if T has ever been added
on an entity before the registration.
Indirect requirements through other components are allowed. In those cases, any existing requirements will only be overwritten if the new requirement is more specific.
§Example
#[derive(Component)]
struct A;
#[derive(Component, Default, PartialEq, Eq, Debug)]
struct B(usize);
#[derive(Component, Default, PartialEq, Eq, Debug)]
struct C(u32);
// Register B as required by A and C as required by B.
app.register_required_components::<A, B>();
app.register_required_components::<B, C>();
// Duplicate registration! This will fail.
assert!(app.try_register_required_components::<A, B>().is_err());
fn setup(mut commands: Commands) {
// This will implicitly also insert B and C with their Default constructors.
commands.spawn(A);
}
fn validate(query: Option<Single<(&A, &B, &C)>>) {
let (a, b, c) = query.unwrap().into_inner();
assert_eq!(b, &B(0));
assert_eq!(c, &C(0));
}Sourcepub fn try_register_required_components_with<T, R>(
&mut self,
constructor: fn() -> R,
) -> Result<(), RequiredComponentsError>
pub fn try_register_required_components_with<T, R>( &mut self, constructor: fn() -> R, ) -> Result<(), RequiredComponentsError>
Tries to register the given component R as a required component for T.
When T is added to an entity, R and its own required components will also be added
if R was not already provided. The given constructor will be used for the creation of R.
If a Default constructor is desired, use App::register_required_components instead.
For the panicking version, see App::register_required_components_with.
Note that requirements must currently be registered before T is inserted into the world
for the first time. Commonly, this is done in plugins. This limitation may be fixed in the future.
§Errors
Returns a RequiredComponentsError if R is already a directly required component for T, or if T has ever been added
on an entity before the registration.
Indirect requirements through other components are allowed. In those cases, any existing requirements will only be overwritten if the new requirement is more specific.
§Example
#[derive(Component)]
struct A;
#[derive(Component, Default, PartialEq, Eq, Debug)]
struct B(usize);
#[derive(Component, Default, PartialEq, Eq, Debug)]
struct C(u32);
// Register B and C as required by A and C as required by B.
// A requiring C directly will overwrite the indirect requirement through B.
app.register_required_components::<A, B>();
app.register_required_components_with::<B, C>(|| C(1));
app.register_required_components_with::<A, C>(|| C(2));
// Duplicate registration! Even if the constructors were different, this would fail.
assert!(app.try_register_required_components_with::<B, C>(|| C(1)).is_err());
fn setup(mut commands: Commands) {
// This will implicitly also insert B with its Default constructor and C
// with the custom constructor defined by A.
commands.spawn(A);
}
fn validate(query: Option<Single<(&A, &B, &C)>>) {
let (a, b, c) = query.unwrap().into_inner();
assert_eq!(b, &B(0));
assert_eq!(c, &C(2));
}Sourcepub fn register_disabling_component<C>(&mut self)where
C: Component,
pub fn register_disabling_component<C>(&mut self)where
C: Component,
Registers a component type as “disabling”, using default query filters to exclude entities with the component from queries.
§Warning
As discussed in the module docs, this can have performance implications, as well as create interoperability issues, and should be used with caution.
Sourcepub fn world(&self) -> &World
pub fn world(&self) -> &World
Returns a reference to the main SubApp’s World. This is the same as calling
app.main().world().
Sourcepub fn world_mut(&mut self) -> &mut World
pub fn world_mut(&mut self) -> &mut World
Returns a mutable reference to the main SubApp’s World. This is the same as calling
app.main_mut().world_mut().
Examples found in repository?
More examples
7fn main() {
8 let mut app = App::new();
9
10 app
11 // to display log messages from Stepping resource
12 .add_plugins(LogPlugin::default())
13 .add_systems(
14 Update,
15 (
16 update_system_one,
17 // establish a dependency here to simplify descriptions below
18 update_system_two.after(update_system_one),
19 update_system_three.after(update_system_two),
20 update_system_four,
21 ),
22 )
23 .add_systems(PreUpdate, pre_update_system);
24
25 // For the simplicity of this example, we directly modify the `Stepping`
26 // resource here and run the systems with `App::update()`. Each call to
27 // `App::update()` is the equivalent of a single frame render when using
28 // `App::run()`.
29 //
30 // In a real-world situation, the `Stepping` resource would be modified by
31 // a system based on input from the user. A full demonstration of this can
32 // be found in the breakout example.
33 println!(
34 r#"
35 Actions: call app.update()
36 Result: All systems run normally"#
37 );
38 app.update();
39
40 println!(
41 r#"
42 Actions: Add the Stepping resource then call app.update()
43 Result: All systems run normally. Stepping has no effect unless explicitly
44 configured for a Schedule, and Stepping has been enabled."#
45 );
46 app.insert_resource(Stepping::new());
47 app.update();
48
49 println!(
50 r#"
51 Actions: Add the Update Schedule to Stepping; enable Stepping; call
52 app.update()
53 Result: Only the systems in PreUpdate run. When Stepping is enabled,
54 systems in the configured schedules will not run unless:
55 * Stepping::step_frame() is called
56 * Stepping::continue_frame() is called
57 * System has been configured to always run"#
58 );
59 let mut stepping = app.world_mut().resource_mut::<Stepping>();
60 stepping.add_schedule(Update).enable();
61 app.update();
62
63 println!(
64 r#"
65 Actions: call Stepping.step_frame(); call app.update()
66 Result: The PreUpdate systems run, and one Update system will run. In
67 Stepping, step means run the next system across all the schedules
68 that have been added to the Stepping resource."#
69 );
70 let mut stepping = app.world_mut().resource_mut::<Stepping>();
71 stepping.step_frame();
72 app.update();
73
74 println!(
75 r#"
76 Actions: call app.update()
77 Result: Only the PreUpdate systems run. The previous call to
78 Stepping::step_frame() only applies for the next call to
79 app.update()/the next frame rendered.
80 "#
81 );
82 app.update();
83
84 println!(
85 r#"
86 Actions: call Stepping::continue_frame(); call app.update()
87 Result: PreUpdate system will run, and all remaining Update systems will
88 run. Stepping::continue_frame() tells stepping to run all systems
89 starting after the last run system until it hits the end of the
90 frame, or it encounters a system with a breakpoint set. In this
91 case, we previously performed a step, running one system in Update.
92 This continue will cause all remaining systems in Update to run."#
93 );
94 let mut stepping = app.world_mut().resource_mut::<Stepping>();
95 stepping.continue_frame();
96 app.update();
97
98 println!(
99 r#"
100 Actions: call Stepping::step_frame() & app.update() four times in a row
101 Result: PreUpdate system runs every time we call app.update(), along with
102 one system from the Update schedule each time. This shows what
103 execution would look like to step through an entire frame of
104 systems."#
105 );
106 for _ in 0..4 {
107 let mut stepping = app.world_mut().resource_mut::<Stepping>();
108 stepping.step_frame();
109 app.update();
110 }
111
112 println!(
113 r#"
114 Actions: Stepping::always_run(Update, update_system_two); step through all
115 systems
116 Result: PreUpdate system and update_system_two() will run every time we
117 call app.update(). We'll also only need to step three times to
118 execute all systems in the frame. Stepping::always_run() allows
119 us to granularly allow systems to run when stepping is enabled."#
120 );
121 let mut stepping = app.world_mut().resource_mut::<Stepping>();
122 stepping.always_run(Update, update_system_two);
123 for _ in 0..3 {
124 let mut stepping = app.world_mut().resource_mut::<Stepping>();
125 stepping.step_frame();
126 app.update();
127 }
128
129 println!(
130 r#"
131 Actions: Stepping::never_run(Update, update_system_two); continue through
132 all systems
133 Result: All systems except update_system_two() will execute.
134 Stepping::never_run() allows us to disable systems while Stepping
135 is enabled."#
136 );
137 let mut stepping = app.world_mut().resource_mut::<Stepping>();
138 stepping.never_run(Update, update_system_two);
139 stepping.continue_frame();
140 app.update();
141
142 println!(
143 r#"
144 Actions: Stepping::set_breakpoint(Update, update_system_two); continue,
145 step, continue
146 Result: During the first continue, pre_update_system() and
147 update_system_one() will run. update_system_four() may also run
148 as it has no dependency on update_system_two() or
149 update_system_three(). Nether update_system_two() nor
150 update_system_three() will run in the first app.update() call as
151 they form a chained dependency on update_system_one() and run
152 in order of one, two, three. Stepping stops system execution in
153 the Update schedule when it encounters the breakpoint for
154 update_system_two().
155 During the step we run update_system_two() along with the
156 pre_update_system().
157 During the final continue pre_update_system() and
158 update_system_three() run."#
159 );
160 let mut stepping = app.world_mut().resource_mut::<Stepping>();
161 stepping.set_breakpoint(Update, update_system_two);
162 stepping.continue_frame();
163 app.update();
164 let mut stepping = app.world_mut().resource_mut::<Stepping>();
165 stepping.step_frame();
166 app.update();
167 let mut stepping = app.world_mut().resource_mut::<Stepping>();
168 stepping.continue_frame();
169 app.update();
170
171 println!(
172 r#"
173 Actions: Stepping::clear_breakpoint(Update, update_system_two); continue
174 through all systems
175 Result: All systems will run"#
176 );
177 let mut stepping = app.world_mut().resource_mut::<Stepping>();
178 stepping.clear_breakpoint(Update, update_system_two);
179 stepping.continue_frame();
180 app.update();
181
182 println!(
183 r#"
184 Actions: Stepping::disable(); app.update()
185 Result: All systems will run. With Stepping disabled, there's no need to
186 call Stepping::step_frame() or Stepping::continue_frame() to run
187 systems in the Update schedule."#
188 );
189 let mut stepping = app.world_mut().resource_mut::<Stepping>();
190 stepping.disable();
191 app.update();
192}Sourcepub fn sub_apps_mut(&mut self) -> &mut SubApps
pub fn sub_apps_mut(&mut self) -> &mut SubApps
Returns a mutable reference to the SubApps collection.
Sourcepub fn sub_app_mut(&mut self, label: impl AppLabel) -> &mut SubApp
pub fn sub_app_mut(&mut self, label: impl AppLabel) -> &mut SubApp
Sourcepub fn get_sub_app(&self, label: impl AppLabel) -> Option<&SubApp>
pub fn get_sub_app(&self, label: impl AppLabel) -> Option<&SubApp>
Returns a reference to the SubApp with the given label, if it exists.
Sourcepub fn get_sub_app_mut(&mut self, label: impl AppLabel) -> Option<&mut SubApp>
pub fn get_sub_app_mut(&mut self, label: impl AppLabel) -> Option<&mut SubApp>
Returns a mutable reference to the SubApp with the given label, if it exists.
Sourcepub fn insert_sub_app(&mut self, label: impl AppLabel, sub_app: SubApp)
pub fn insert_sub_app(&mut self, label: impl AppLabel, sub_app: SubApp)
Inserts a SubApp with the given label.
Sourcepub fn remove_sub_app(&mut self, label: impl AppLabel) -> Option<SubApp>
pub fn remove_sub_app(&mut self, label: impl AppLabel) -> Option<SubApp>
Removes the SubApp with the given label, if it exists.
Sourcepub fn update_sub_app_by_label(&mut self, label: impl AppLabel)
pub fn update_sub_app_by_label(&mut self, label: impl AppLabel)
Extract data from the main world into the SubApp with the given label and perform an update if it exists.
Sourcepub fn add_schedule(&mut self, schedule: Schedule) -> &mut App
pub fn add_schedule(&mut self, schedule: Schedule) -> &mut App
Inserts a new schedule under the provided label, overwriting any existing
schedule with the same label.
Sourcepub fn init_schedule(&mut self, label: impl ScheduleLabel) -> &mut App
pub fn init_schedule(&mut self, label: impl ScheduleLabel) -> &mut App
Initializes an empty schedule under the provided label, if it does not exist.
See add_schedule to insert an existing schedule.
Sourcepub fn get_schedule(&self, label: impl ScheduleLabel) -> Option<&Schedule>
pub fn get_schedule(&self, label: impl ScheduleLabel) -> Option<&Schedule>
Returns a reference to the Schedule with the provided label if it exists.
Sourcepub fn get_schedule_mut(
&mut self,
label: impl ScheduleLabel,
) -> Option<&mut Schedule>
pub fn get_schedule_mut( &mut self, label: impl ScheduleLabel, ) -> Option<&mut Schedule>
Returns a mutable reference to the Schedule with the provided label if it exists.
Sourcepub fn edit_schedule(
&mut self,
label: impl ScheduleLabel,
f: impl FnMut(&mut Schedule),
) -> &mut App
pub fn edit_schedule( &mut self, label: impl ScheduleLabel, f: impl FnMut(&mut Schedule), ) -> &mut App
Runs function f with the Schedule associated with label.
Note: This will create the schedule if it does not already exist.
Sourcepub fn configure_schedules(
&mut self,
schedule_build_settings: ScheduleBuildSettings,
) -> &mut App
pub fn configure_schedules( &mut self, schedule_build_settings: ScheduleBuildSettings, ) -> &mut App
Applies the provided ScheduleBuildSettings to all schedules.
This mutates all currently present schedules, but does not apply to any custom schedules that might be added in the future.
Sourcepub fn allow_ambiguous_component<T>(&mut self) -> &mut Appwhere
T: Component,
pub fn allow_ambiguous_component<T>(&mut self) -> &mut Appwhere
T: Component,
When doing ambiguity checking this
ignores systems that are ambiguous on Component T.
This settings only applies to the main world. To apply this to other worlds call the corresponding method on World
§Example
#[derive(Component)]
struct A;
// these systems are ambiguous on A
fn system_1(_: Query<&mut A>) {}
fn system_2(_: Query<&A>) {}
let mut app = App::new();
app.configure_schedules(ScheduleBuildSettings {
ambiguity_detection: LogLevel::Error,
..default()
});
app.add_systems(Update, ( system_1, system_2 ));
app.allow_ambiguous_component::<A>();
// running the app does not error.
app.update();Sourcepub fn allow_ambiguous_resource<T>(&mut self) -> &mut Appwhere
T: Resource,
pub fn allow_ambiguous_resource<T>(&mut self) -> &mut Appwhere
T: Resource,
When doing ambiguity checking this
ignores systems that are ambiguous on Resource T.
This settings only applies to the main world. To apply this to other worlds call the corresponding method on World
§Example
#[derive(Resource)]
struct R;
// these systems are ambiguous on R
fn system_1(_: ResMut<R>) {}
fn system_2(_: Res<R>) {}
let mut app = App::new();
app.configure_schedules(ScheduleBuildSettings {
ambiguity_detection: LogLevel::Error,
..default()
});
app.insert_resource(R);
app.add_systems(Update, ( system_1, system_2 ));
app.allow_ambiguous_resource::<R>();
// running the app does not error.
app.update();Sourcepub fn ignore_ambiguity<M1, M2, S1, S2>(
&mut self,
schedule: impl ScheduleLabel,
a: S1,
b: S2,
) -> &mut Appwhere
S1: IntoSystemSet<M1>,
S2: IntoSystemSet<M2>,
pub fn ignore_ambiguity<M1, M2, S1, S2>(
&mut self,
schedule: impl ScheduleLabel,
a: S1,
b: S2,
) -> &mut Appwhere
S1: IntoSystemSet<M1>,
S2: IntoSystemSet<M2>,
Suppress warnings and errors that would result from systems in these sets having ambiguities
(conflicting access but indeterminate order) with systems in set.
When possible, do this directly in the .add_systems(Update, a.ambiguous_with(b)) call.
However, sometimes two independent plugins A and B are reported as ambiguous, which you
can only suppress as the consumer of both.
Sourcepub fn should_exit(&self) -> Option<AppExit>
pub fn should_exit(&self) -> Option<AppExit>
Sourcepub fn add_observer<E, B, M>(
&mut self,
observer: impl IntoObserverSystem<E, B, M>,
) -> &mut App
pub fn add_observer<E, B, M>( &mut self, observer: impl IntoObserverSystem<E, B, M>, ) -> &mut App
Spawns an Observer entity, which will watch for and respond to the given event.
observer can be any system whose first parameter is On.
§Examples
app.add_observer(|event: On<Party>, friends: Query<Entity, With<Friend>>, mut commands: Commands| {
if event.friends_allowed {
for entity in friends.iter() {
commands.trigger(Invite { entity } );
}
}
});Sourcepub fn get_error_handler(&self) -> Option<fn(BevyError, ErrorContext)>
pub fn get_error_handler(&self) -> Option<fn(BevyError, ErrorContext)>
Gets the error handler to set for new supapps.
Note that the error handler of existing subapps may differ.
Sourcepub fn set_error_handler(
&mut self,
handler: fn(BevyError, ErrorContext),
) -> &mut App
pub fn set_error_handler( &mut self, handler: fn(BevyError, ErrorContext), ) -> &mut App
Set the default error handler for the all subapps (including the main one and future ones) that do not have one.
May only be called once and should be set by the application, not by libraries.
The handler will be called when an error is produced and not otherwise handled.
§Panics
Panics if called multiple times.
§Example
App::new()
.set_error_handler(warn)
.add_plugins(MyPlugins)
.run();Trait Implementations§
Source§impl AddAudioSource for App
impl AddAudioSource for App
Source§fn add_audio_source<T>(&mut self) -> &mut App
fn add_audio_source<T>(&mut self) -> &mut App
Source§impl AddRenderCommand for App
impl AddRenderCommand for App
Source§fn add_render_command<P, C>(&mut self) -> &mut Appwhere
P: PhaseItem,
C: RenderCommand<P> + Send + Sync + 'static,
<C as RenderCommand<P>>::Param: ReadOnlySystemParam,
fn add_render_command<P, C>(&mut self) -> &mut Appwhere
P: PhaseItem,
C: RenderCommand<P> + Send + Sync + 'static,
<C as RenderCommand<P>>::Param: ReadOnlySystemParam,
RenderCommand for the specified render phase to the app.Source§impl AppExtStates for App
impl AppExtStates for App
Source§fn init_state<S>(&mut self) -> &mut Appwhere
S: FreelyMutableState + FromWorld,
fn init_state<S>(&mut self) -> &mut Appwhere
S: FreelyMutableState + FromWorld,
Source§fn insert_state<S>(&mut self, state: S) -> &mut Appwhere
S: FreelyMutableState,
fn insert_state<S>(&mut self, state: S) -> &mut Appwhere
S: FreelyMutableState,
Source§fn add_computed_state<S>(&mut self) -> &mut Appwhere
S: ComputedStates,
fn add_computed_state<S>(&mut self) -> &mut Appwhere
S: ComputedStates,
ComputedStates. Read moreSource§fn add_sub_state<S>(&mut self) -> &mut Appwhere
S: SubStates,
fn add_sub_state<S>(&mut self) -> &mut Appwhere
S: SubStates,
Source§fn register_type_state<S>(&mut self) -> &mut App
fn register_type_state<S>(&mut self) -> &mut App
bevy_reflect only.T using App::register_type,
and adds ReflectState type data to T in the type registry. Read moreSource§fn register_type_mutable_state<S>(&mut self) -> &mut App
fn register_type_mutable_state<S>(&mut self) -> &mut App
bevy_reflect only.T using App::register_type,
and adds crate::reflect::ReflectState and crate::reflect::ReflectFreelyMutableState type data to T in the type registry. Read moreSource§impl AppGizmoBuilder for App
impl AppGizmoBuilder for App
Source§fn init_gizmo_group<Config>(&mut self) -> &mut Appwhere
Config: GizmoConfigGroup,
fn init_gizmo_group<Config>(&mut self) -> &mut Appwhere
Config: GizmoConfigGroup,
Source§fn insert_gizmo_config<Config>(
&mut self,
group: Config,
config: GizmoConfig,
) -> &mut Appwhere
Config: GizmoConfigGroup,
fn insert_gizmo_config<Config>(
&mut self,
group: Config,
config: GizmoConfig,
) -> &mut Appwhere
Config: GizmoConfigGroup,
Source§impl AssetApp for App
impl AssetApp for App
Source§fn register_asset_loader<L>(&mut self, loader: L) -> &mut Appwhere
L: AssetLoader,
fn register_asset_loader<L>(&mut self, loader: L) -> &mut Appwhere
L: AssetLoader,
Source§fn register_asset_processor<P>(&mut self, processor: P) -> &mut Appwhere
P: Process,
fn register_asset_processor<P>(&mut self, processor: P) -> &mut Appwhere
P: Process,
Source§fn register_asset_source(
&mut self,
id: impl Into<AssetSourceId<'static>>,
source: AssetSourceBuilder,
) -> &mut App
fn register_asset_source( &mut self, id: impl Into<AssetSourceId<'static>>, source: AssetSourceBuilder, ) -> &mut App
Source§fn set_default_asset_processor<P>(&mut self, extension: &str) -> &mut Appwhere
P: Process,
fn set_default_asset_processor<P>(&mut self, extension: &str) -> &mut Appwhere
P: Process,
extension.Source§fn init_asset_loader<L>(&mut self) -> &mut Appwhere
L: AssetLoader + FromWorld,
fn init_asset_loader<L>(&mut self) -> &mut Appwhere
L: AssetLoader + FromWorld,
App’s AssetServer.Source§fn init_asset<A>(&mut self) -> &mut Appwhere
A: Asset,
fn init_asset<A>(&mut self) -> &mut Appwhere
A: Asset,
Source§fn register_asset_reflect<A>(&mut self) -> &mut App
fn register_asset_reflect<A>(&mut self) -> &mut App
T using [App::register],
and adds ReflectAsset type data to T and ReflectHandle type data to Handle<T> in the type registry. Read moreSource§fn preregister_asset_loader<L>(&mut self, extensions: &[&str]) -> &mut Appwhere
L: AssetLoader,
fn preregister_asset_loader<L>(&mut self, extensions: &[&str]) -> &mut Appwhere
L: AssetLoader,
Source§impl GetAssetServer for App
impl GetAssetServer for App
fn get_asset_server(&self) -> &AssetServer
Source§impl RegisterDiagnostic for App
impl RegisterDiagnostic for App
Source§fn register_diagnostic(&mut self, diagnostic: Diagnostic) -> &mut App
fn register_diagnostic(&mut self, diagnostic: Diagnostic) -> &mut App
Source§impl RenderGraphExt for App
impl RenderGraphExt for App
Source§fn add_render_graph_node<T>(
&mut self,
sub_graph: impl RenderSubGraph,
node_label: impl RenderLabel,
) -> &mut App
fn add_render_graph_node<T>( &mut self, sub_graph: impl RenderSubGraph, node_label: impl RenderLabel, ) -> &mut App
Source§fn add_render_graph_edge(
&mut self,
sub_graph: impl RenderSubGraph,
output_node: impl RenderLabel,
input_node: impl RenderLabel,
) -> &mut App
fn add_render_graph_edge( &mut self, sub_graph: impl RenderSubGraph, output_node: impl RenderLabel, input_node: impl RenderLabel, ) -> &mut App
Source§fn add_render_graph_edges<const N: usize>(
&mut self,
sub_graph: impl RenderSubGraph,
edges: impl IntoRenderNodeArray<N>,
) -> &mut App
fn add_render_graph_edges<const N: usize>( &mut self, sub_graph: impl RenderSubGraph, edges: impl IntoRenderNodeArray<N>, ) -> &mut App
fn add_render_sub_graph(&mut self, sub_graph: impl RenderSubGraph) -> &mut App
Source§impl StateScopedMessagesAppExt for App
impl StateScopedMessagesAppExt for App
Auto Trait Implementations§
impl !Freeze for App
impl !RefUnwindSafe for App
impl !Send for App
impl !Sync for App
impl Unpin for App
impl !UnwindSafe for App
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Source§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<Ret> SpawnIfAsync<(), Ret> for Ret
impl<Ret> SpawnIfAsync<(), Ret> for Ret
Source§impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
Source§fn super_from(input: T) -> O
fn super_from(input: T) -> O
Source§impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
Source§fn super_into(self) -> O
fn super_into(self) -> O
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.