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/2d/sprite.rs
- examples/2d/sprite_flipping.rs
- examples/2d/sprite_slice.rs
- examples/2d/transparency_2d.rs
- examples/3d/3d_scene.rs
- examples/3d/orthographic.rs
- examples/3d/texture.rs
- examples/3d/two_passes.rs
- examples/3d/vertex_colors.rs
- examples/animation/eased_motion.rs
- examples/asset/asset_loading.rs
- examples/asset/hot_asset_reloading.rs
- examples/asset/repeated_texture.rs
- examples/audio/audio.rs
- examples/camera/custom_projection.rs
- examples/reflection/reflection_types.rs
- examples/ui/borders.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/ecs/startup_system.rs
- examples/input/char_input_events.rs
- examples/app/drag_and_drop.rs
- examples/input/mouse_input_events.rs
- examples/input/keyboard_input_events.rs
- examples/2d/mesh2d_manual.rs
- examples/asset/embedded_asset.rs
- examples/shader/custom_shader_instancing.rs
- examples/3d/decal.rs
- examples/shader/custom_render_phase.rs
- examples/asset/custom_asset_reader.rs
- examples/picking/simple_picking.rs
- examples/2d/mesh2d_repeated_texture.rs
- examples/input/mouse_input.rs
- examples/input/gamepad_input_events.rs
- examples/ecs/hierarchy.rs
- examples/2d/sprite_tile.rs
- examples/app/without_winit.rs
- examples/ecs/immutable_components.rs
- examples/transforms/translation.rs
- examples/3d/3d_viewport_to_world.rs
- examples/transforms/3d_rotation.rs
- examples/3d/generate_custom_mesh.rs
- examples/3d/lines.rs
- examples/3d/parenting.rs
- examples/animation/easing_functions.rs
- examples/stress_tests/many_cameras_lights.rs
- examples/ui/render_ui_to_texture.rs
- examples/2d/move_sprite.rs
- examples/shader/animate_shader.rs
- examples/shader/custom_vertex_attribute.rs
- examples/shader/shader_defs.rs
- examples/shader/shader_material.rs
- examples/shader/shader_material_glsl.rs
- examples/3d/animated_material.rs
- examples/3d/transparency_3d.rs
- examples/ecs/system_param.rs
- tests/3d/no_prepass.rs
- examples/ui/transparency_ui.rs
- examples/ui/z_index.rs
- examples/2d/bloom_2d.rs
- examples/3d/load_gltf_extras.rs
- examples/shader/specialized_mesh_pipeline.rs
- examples/3d/order_independent_transparency.rs
- examples/3d/query_gltf_primitives.rs
- examples/3d/pbr.rs
- examples/gizmos/axes.rs
- examples/math/random_sampling.rs
- examples/app/thread_pool_resources.rs
- examples/audio/audio_control.rs
- examples/ecs/parallel_query.rs
- examples/3d/camera_sub_view.rs
- examples/movement/smooth_follow.rs
- examples/transforms/scale.rs
- examples/3d/render_to_texture.rs
- examples/3d/rotate_environment_map.rs
- examples/3d/split_screen.rs
- examples/3d/blend_modes.rs
- examples/app/custom_loop.rs
- examples/async_tasks/async_compute.rs
- examples/window/screenshot.rs
- examples/3d/bloom_3d.rs
- examples/shader/custom_post_processing.rs
- examples/3d/atmosphere.rs
- examples/3d/edit_material_on_gltf.rs
- examples/shader/automatic_instancing.rs
- examples/shader/shader_material_2d.rs
- examples/shader/shader_material_bindless.rs
- examples/shader/storage_buffer.rs
- examples/gizmos/light_gizmos.rs
- examples/shader/fallback_image.rs
- examples/shader/shader_material_screenspace_texture.rs
- examples/app/log_layers.rs
- examples/3d/auto_exposure.rs
- examples/camera/camera_orbit.rs
- examples/3d/mesh_ray_cast.rs
- examples/3d/anti_aliasing.rs
- examples/ui/ghost_nodes.rs
- examples/audio/pitch.rs
- examples/time/timers.rs
- examples/3d/spherical_area_lights.rs
- examples/2d/sprite_sheet.rs
- examples/reflection/reflection.rs
- examples/ui/ui_material.rs
- examples/window/multiple_windows.rs
- examples/camera/2d_top_down_camera.rs
- examples/reflection/generic_reflection.rs
- examples/audio/soundtrack.rs
- examples/camera/2d_screen_shake.rs
- examples/picking/sprite_picking.rs
- examples/ui/text.rs
- examples/window/clear_color.rs
- examples/gizmos/2d_gizmos.rs
- examples/3d/update_gltf_scene.rs
- examples/2d/text2d.rs
- examples/3d/load_gltf.rs
- examples/ecs/component_hooks.rs
- examples/ui/size_constraints.rs
- examples/2d/pixel_grid_snap.rs
- examples/ui/scroll.rs
- examples/animation/animation_events.rs
- examples/3d/motion_blur.rs
- examples/audio/spatial_audio_3d.rs
- examples/2d/sprite_scale.rs
- examples/3d/atmospheric_fog.rs
- examples/asset/asset_decompression.rs
- examples/animation/animated_transform.rs
- examples/shader/array_texture.rs
- examples/gizmos/3d_gizmos.rs
- examples/picking/mesh_picking.rs
- examples/animation/animated_ui.rs
- examples/shader/texture_binding_array.rs
- examples/transforms/align.rs
- examples/animation/gltf_skinned_mesh.rs
- examples/animation/custom_skinned_mesh.rs
- examples/shader/shader_material_wesl.rs
- examples/ui/box_shadow.rs
- examples/ui/overflow_clip_margin.rs
- examples/ui/font_atlas_debug.rs
- examples/window/monitor_info.rs
- examples/testbed/full_ui.rs
- examples/shader/extended_material.rs
- examples/2d/2d_viewport_to_world.rs
- examples/3d/spotlight.rs
- examples/ecs/iter_combinations.rs
- examples/3d/ssao.rs
- examples/2d/mesh2d_arcs.rs
- examples/3d/fog.rs
- examples/shader/extended_material_bindless.rs
- examples/audio/decodable.rs
- examples/2d/2d_shapes.rs
- examples/async_tasks/external_source_external_thread.rs
- examples/ui/button.rs
- examples/ui/ui_texture_atlas_slice.rs
- examples/ui/ui_texture_slice.rs
- examples/ui/overflow.rs
- examples/3d/clearcoat.rs
- examples/diagnostics/enabling_disabling_diagnostic.rs
- examples/app/no_renderer.rs
- examples/ui/ui_texture_slice_flip_and_tile.rs
- examples/audio/spatial_audio_2d.rs
- examples/ui/relative_cursor_position.rs
- examples/animation/animated_mesh.rs
- examples/ecs/change_detection.rs
- examples/ecs/entity_disabling.rs
- examples/ecs/removal_detection.rs
- examples/input/text_input.rs
- examples/camera/first_person_view_model.rs
- examples/ui/flex_layout.rs
- examples/app/plugin.rs
- examples/shader/gpu_readback.rs
- examples/transforms/transform.rs
- examples/ecs/custom_query_param.rs
- examples/animation/animated_mesh_control.rs
- examples/asset/asset_settings.rs
- examples/asset/custom_asset.rs
- examples/games/contributors.rs
- examples/3d/parallax_mapping.rs
- examples/asset/alter_mesh.rs
- examples/asset/alter_sprite.rs
- examples/ui/tab_navigation.rs
- examples/scene/scene.rs
- examples/2d/rotation.rs
- examples/3d/skybox.rs
- examples/2d/texture_atlas.rs
- examples/ui/grid.rs
- examples/3d/deferred_rendering.rs
- examples/ecs/observer_propagation.rs
- examples/3d/color_grading.rs
- examples/window/window_resizing.rs
- examples/3d/fog_volumes.rs
- examples/time/time.rs
- examples/3d/lighting.rs
- examples/ecs/one_shot_systems.rs
- examples/ui/ui_scaling.rs
- examples/3d/shadow_biases.rs
- examples/animation/color_animation.rs
- examples/app/return_after_run.rs
- examples/window/custom_cursor_image.rs
- examples/app/log_layers_ecs.rs
- examples/window/window_drag_move.rs
- examples/ecs/fixed_timestep.rs
- examples/3d/3d_shapes.rs
- examples/3d/scrolling_fog.rs
- examples/3d/shadow_caster_receiver.rs
- examples/ui/display_and_visibility.rs
- examples/ui/text_debug.rs
- tests/window/minimizing.rs
- examples/window/scale_factor_override.rs
- examples/animation/morph_targets.rs
- examples/animation/animated_mesh_events.rs
- examples/app/logs.rs
- examples/remote/server.rs
- examples/diagnostics/custom_diagnostic.rs
- examples/games/loading_screen.rs
- examples/math/sampling_primitives.rs
- examples/games/game_menu.rs
- examples/3d/volumetric_fog.rs
- examples/3d/lightmaps.rs
- examples/math/cubic_splines.rs
- examples/2d/cpu_draw.rs
- examples/3d/depth_of_field.rs
- examples/ui/overflow_debug.rs
- examples/3d/anisotropy.rs
- examples/ui/ui_texture_atlas.rs
- examples/asset/extra_source.rs
- examples/3d/visibility_range.rs
- examples/3d/reflection_probes.rs
- examples/math/custom_primitives.rs
- examples/ui/viewport_debug.rs
- examples/ecs/generic_system.rs
- examples/3d/post_processing.rs
- examples/2d/sprite_animation.rs
- examples/window/custom_user_event.rs
- examples/testbed/2d.rs
- examples/testbed/3d.rs
- examples/animation/animation_masks.rs
- examples/3d/meshlet.rs
- examples/app/plugin_group.rs
- examples/3d/specular_tint.rs
- examples/3d/transmission.rs
- examples/ui/window_fallthrough.rs
- tests/window/resizing.rs
- examples/shader/custom_phase_item.rs
- examples/2d/custom_gltf_vertex_attribute.rs
- examples/stress_tests/text_pipeline.rs
- examples/ecs/send_and_receive_events.rs
- examples/ui/text_wrap_debug.rs
- examples/shader/shader_prepass.rs
- examples/testbed/ui.rs
- examples/3d/ssr.rs
- examples/animation/animation_graph.rs
- examples/math/bounding_2d.rs
- examples/stress_tests/many_lights.rs
- examples/window/transparent_window.rs
- examples/shader/compute_shader_game_of_life.rs
- examples/games/alien_cake_addict.rs
- examples/ecs/fallible_params.rs
- examples/stress_tests/many_text2d.rs
- examples/stress_tests/many_materials.rs
- examples/stress_tests/many_gizmos.rs
- examples/games/breakout.rs
- examples/3d/pcss.rs
- examples/ecs/system_piping.rs
- examples/stress_tests/many_glyphs.rs
- examples/3d/tonemapping.rs
- examples/picking/debug_picking.rs
- examples/state/custom_transitions.rs
- examples/camera/projection_zoom.rs
- examples/time/virtual_time.rs
- examples/asset/multi_asset_sync.rs
- examples/stress_tests/many_animated_sprites.rs
- examples/stress_tests/many_cubes.rs
- examples/dev_tools/fps_overlay.rs
- examples/3d/occlusion_culling.rs
- examples/stress_tests/many_sprites.rs
- examples/state/states.rs
- examples/app/headless.rs
- examples/3d/mixed_lighting.rs
- examples/3d/clustered_decals.rs
- examples/window/low_power.rs
- examples/state/sub_states.rs
- examples/games/desk_toy.rs
- examples/diagnostics/log_diagnostics.rs
- examples/3d/wireframe.rs
- tests/ecs/ambiguity_detection.rs
- examples/stress_tests/transform_hierarchy.rs
- examples/2d/wireframe_2d.rs
- examples/asset/processing/asset_processing.rs
- examples/movement/physics_in_fixed_timestep.rs
- examples/stress_tests/many_foxes.rs
- examples/app/headless_renderer.rs
- examples/math/render_primitives.rs
- examples/ecs/event.rs
- examples/stress_tests/bevymark.rs
- examples/ecs/observers.rs
- examples/ecs/system_closure.rs
- examples/ui/directional_navigation.rs
- examples/window/window_settings.rs
- examples/ecs/error_handling.rs
- examples/stress_tests/many_buttons.rs
- examples/3d/irradiance_volumes.rs
- examples/ecs/nondeterministic_system_order.rs
- examples/ecs/custom_schedule.rs
- examples/state/computed_states.rs
- examples/ecs/run_conditions.rs
- examples/ecs/ecs_guide.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?
10fn my_runner(mut app: App) -> AppExit {
11 // Finalize plugin building, including running any necessary clean-up.
12 // This is normally completed by the default runner.
13 app.finish();
14 app.cleanup();
15
16 println!("Type stuff into the console");
17 for line in io::stdin().lines() {
18 {
19 let mut input = app.world_mut().resource_mut::<Input>();
20 input.0 = line.unwrap();
21 }
22 app.update();
23
24 if let Some(exit) = app.should_exit() {
25 return exit;
26 }
27 }
28
29 AppExit::Success
30}
More examples
24fn main() {
25 let mut app = App::new();
26 app.add_plugins(MinimalPlugins)
27 .add_event::<DebugEvent>()
28 .add_event::<A>()
29 .add_event::<B>()
30 .add_systems(Update, read_and_write_different_event_types)
31 .add_systems(
32 Update,
33 (
34 send_events,
35 debug_events,
36 send_and_receive_param_set,
37 debug_events,
38 send_and_receive_manual_event_reader,
39 debug_events,
40 )
41 .chain(),
42 );
43 // We're just going to run a few frames, so we can see and understand the output.
44 app.update();
45 // By running for longer than one frame, we can see that we're caching our cursor in the event queue properly.
46 app.update();
47}
14fn main() {
15 let mut app = App::new();
16 app.add_plugins(DefaultPlugins);
17
18 let main_app = app.main_mut();
19 configure_ambiguity_detection(main_app);
20 let render_extract_app = app.sub_app_mut(RenderExtractApp);
21 configure_ambiguity_detection(render_extract_app);
22
23 // Ambiguities in the RenderApp are currently allowed.
24 // Eventually, we should forbid these: see https://github.com/bevyengine/bevy/issues/7386
25 // Uncomment the lines below to show the current ambiguities in the RenderApp.
26 // let sub_app = app.sub_app_mut(bevy_render::RenderApp);
27 // configure_ambiguity_detection(sub_app);
28
29 app.finish();
30 app.cleanup();
31 app.update();
32
33 let main_app_ambiguities = count_ambiguities(app.main());
34 assert_eq!(
35 main_app_ambiguities.total(),
36 0,
37 "Main app has unexpected ambiguities among the following schedules: \n{main_app_ambiguities:#?}.",
38 );
39
40 // RenderApp is not checked here, because it is not within the App at this point.
41 let render_extract_ambiguities = count_ambiguities(app.sub_app(RenderExtractApp));
42 assert_eq!(
43 render_extract_ambiguities.total(),
44 0,
45 "RenderExtract app has unexpected ambiguities among the following schedules: \n{render_extract_ambiguities:#?}",
46 );
47}
35fn runner(mut app: App) -> AppExit {
36 banner();
37 help();
38 let stdin = io::stdin();
39 for line in stdin.lock().lines() {
40 if let Err(err) = line {
41 println!("read err: {err:#}");
42 break;
43 }
44 match line.unwrap().as_str() {
45 "" => {
46 app.update();
47 }
48 "f" => {
49 println!("FAST: setting relative speed to 2x");
50 app.world_mut()
51 .resource_mut::<Time<Virtual>>()
52 .set_relative_speed(2.0);
53 }
54 "n" => {
55 println!("NORMAL: setting relative speed to 1x");
56 app.world_mut()
57 .resource_mut::<Time<Virtual>>()
58 .set_relative_speed(1.0);
59 }
60 "s" => {
61 println!("SLOW: setting relative speed to 0.5x");
62 app.world_mut()
63 .resource_mut::<Time<Virtual>>()
64 .set_relative_speed(0.5);
65 }
66 "p" => {
67 println!("PAUSE: pausing virtual clock");
68 app.world_mut().resource_mut::<Time<Virtual>>().pause();
69 }
70 "u" => {
71 println!("UNPAUSE: resuming virtual clock");
72 app.world_mut().resource_mut::<Time<Virtual>>().unpause();
73 }
74 "q" => {
75 println!("QUITTING!");
76 break;
77 }
78 _ => {
79 help();
80 }
81 }
82 }
83
84 AppExit::Success
85}
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_three().
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/2d/sprite.rs
- examples/2d/sprite_flipping.rs
- examples/2d/sprite_slice.rs
- examples/2d/transparency_2d.rs
- examples/3d/3d_scene.rs
- examples/3d/orthographic.rs
- examples/3d/texture.rs
- examples/3d/two_passes.rs
- examples/3d/vertex_colors.rs
- examples/animation/eased_motion.rs
- examples/asset/asset_loading.rs
- examples/asset/hot_asset_reloading.rs
- examples/asset/repeated_texture.rs
- examples/audio/audio.rs
- examples/camera/custom_projection.rs
- examples/reflection/reflection_types.rs
- examples/ui/borders.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/ecs/startup_system.rs
- examples/input/char_input_events.rs
- examples/app/drag_and_drop.rs
- examples/input/mouse_input_events.rs
- examples/input/keyboard_input_events.rs
- examples/2d/mesh2d_manual.rs
- examples/asset/embedded_asset.rs
- examples/shader/custom_shader_instancing.rs
- examples/3d/decal.rs
- examples/shader/custom_render_phase.rs
- examples/asset/custom_asset_reader.rs
- examples/picking/simple_picking.rs
- examples/2d/mesh2d_repeated_texture.rs
- examples/input/mouse_input.rs
- examples/input/gamepad_input_events.rs
- examples/ecs/hierarchy.rs
- examples/2d/sprite_tile.rs
- examples/app/without_winit.rs
- examples/ecs/immutable_components.rs
- examples/transforms/translation.rs
- examples/3d/3d_viewport_to_world.rs
- examples/transforms/3d_rotation.rs
- examples/3d/generate_custom_mesh.rs
- examples/3d/lines.rs
- examples/3d/parenting.rs
- examples/animation/easing_functions.rs
- examples/stress_tests/many_cameras_lights.rs
- examples/ui/render_ui_to_texture.rs
- examples/2d/move_sprite.rs
- examples/shader/animate_shader.rs
- examples/shader/custom_vertex_attribute.rs
- examples/shader/shader_defs.rs
- examples/shader/shader_material.rs
- examples/shader/shader_material_glsl.rs
- examples/3d/animated_material.rs
- examples/3d/transparency_3d.rs
- examples/ecs/system_param.rs
- tests/3d/no_prepass.rs
- examples/ui/transparency_ui.rs
- examples/ui/z_index.rs
- examples/2d/bloom_2d.rs
- examples/3d/load_gltf_extras.rs
- examples/shader/specialized_mesh_pipeline.rs
- examples/3d/order_independent_transparency.rs
- examples/3d/query_gltf_primitives.rs
- examples/3d/pbr.rs
- examples/gizmos/axes.rs
- examples/math/random_sampling.rs
- examples/app/thread_pool_resources.rs
- examples/audio/audio_control.rs
- examples/ecs/parallel_query.rs
- examples/3d/camera_sub_view.rs
- examples/movement/smooth_follow.rs
- examples/transforms/scale.rs
- examples/3d/render_to_texture.rs
- examples/3d/rotate_environment_map.rs
- examples/3d/split_screen.rs
- examples/3d/blend_modes.rs
- examples/app/custom_loop.rs
- examples/async_tasks/async_compute.rs
- examples/window/screenshot.rs
- examples/3d/bloom_3d.rs
- examples/shader/custom_post_processing.rs
- examples/3d/atmosphere.rs
- examples/3d/edit_material_on_gltf.rs
- examples/shader/automatic_instancing.rs
- examples/shader/shader_material_2d.rs
- examples/shader/shader_material_bindless.rs
- examples/shader/storage_buffer.rs
- examples/gizmos/light_gizmos.rs
- examples/shader/fallback_image.rs
- examples/shader/shader_material_screenspace_texture.rs
- examples/app/log_layers.rs
- examples/3d/auto_exposure.rs
- examples/camera/camera_orbit.rs
- examples/3d/mesh_ray_cast.rs
- examples/3d/anti_aliasing.rs
- examples/ui/ghost_nodes.rs
- examples/audio/pitch.rs
- examples/time/timers.rs
- examples/3d/spherical_area_lights.rs
- examples/2d/sprite_sheet.rs
- examples/reflection/reflection.rs
- examples/ui/ui_material.rs
- examples/window/multiple_windows.rs
- examples/camera/2d_top_down_camera.rs
- examples/reflection/generic_reflection.rs
- examples/audio/soundtrack.rs
- examples/camera/2d_screen_shake.rs
- examples/picking/sprite_picking.rs
- examples/ui/text.rs
- examples/window/clear_color.rs
- examples/gizmos/2d_gizmos.rs
- examples/3d/update_gltf_scene.rs
- examples/2d/text2d.rs
- examples/3d/load_gltf.rs
- examples/ecs/component_hooks.rs
- examples/ui/size_constraints.rs
- examples/2d/pixel_grid_snap.rs
- examples/ui/scroll.rs
- examples/animation/animation_events.rs
- examples/3d/motion_blur.rs
- examples/audio/spatial_audio_3d.rs
- examples/2d/sprite_scale.rs
- examples/3d/atmospheric_fog.rs
- examples/asset/asset_decompression.rs
- examples/animation/animated_transform.rs
- examples/shader/array_texture.rs
- examples/gizmos/3d_gizmos.rs
- examples/picking/mesh_picking.rs
- examples/animation/animated_ui.rs
- examples/shader/texture_binding_array.rs
- examples/transforms/align.rs
- examples/animation/gltf_skinned_mesh.rs
- examples/animation/custom_skinned_mesh.rs
- examples/shader/shader_material_wesl.rs
- examples/ui/box_shadow.rs
- examples/ui/overflow_clip_margin.rs
- examples/ui/font_atlas_debug.rs
- examples/window/monitor_info.rs
- examples/testbed/full_ui.rs
- examples/shader/extended_material.rs
- examples/2d/2d_viewport_to_world.rs
- examples/3d/spotlight.rs
- examples/ecs/iter_combinations.rs
- examples/3d/ssao.rs
- examples/2d/mesh2d_arcs.rs
- examples/3d/fog.rs
- examples/shader/extended_material_bindless.rs
- examples/audio/decodable.rs
- examples/2d/2d_shapes.rs
- examples/async_tasks/external_source_external_thread.rs
- examples/ui/button.rs
- examples/ui/ui_texture_atlas_slice.rs
- examples/ui/ui_texture_slice.rs
- examples/ui/overflow.rs
- examples/3d/clearcoat.rs
- examples/diagnostics/enabling_disabling_diagnostic.rs
- examples/app/no_renderer.rs
- examples/ui/ui_texture_slice_flip_and_tile.rs
- examples/audio/spatial_audio_2d.rs
- examples/ui/relative_cursor_position.rs
- examples/animation/animated_mesh.rs
- examples/ecs/change_detection.rs
- examples/ecs/entity_disabling.rs
- examples/ecs/removal_detection.rs
- examples/input/text_input.rs
- examples/camera/first_person_view_model.rs
- examples/ui/flex_layout.rs
- examples/app/plugin.rs
- examples/shader/gpu_readback.rs
- examples/transforms/transform.rs
- examples/ecs/custom_query_param.rs
- examples/animation/animated_mesh_control.rs
- examples/asset/asset_settings.rs
- examples/asset/custom_asset.rs
- examples/games/contributors.rs
- examples/3d/parallax_mapping.rs
- examples/asset/alter_mesh.rs
- examples/asset/alter_sprite.rs
- examples/ui/tab_navigation.rs
- examples/scene/scene.rs
- examples/2d/rotation.rs
- examples/3d/skybox.rs
- examples/2d/texture_atlas.rs
- examples/ui/grid.rs
- examples/3d/deferred_rendering.rs
- examples/ecs/observer_propagation.rs
- examples/3d/color_grading.rs
- examples/window/window_resizing.rs
- examples/3d/fog_volumes.rs
- examples/time/time.rs
- examples/3d/lighting.rs
- examples/ecs/one_shot_systems.rs
- examples/ui/ui_scaling.rs
- examples/3d/shadow_biases.rs
- examples/animation/color_animation.rs
- examples/app/return_after_run.rs
- examples/window/custom_cursor_image.rs
- examples/app/log_layers_ecs.rs
- examples/window/window_drag_move.rs
- examples/ecs/fixed_timestep.rs
- examples/3d/3d_shapes.rs
- examples/3d/scrolling_fog.rs
- examples/3d/shadow_caster_receiver.rs
- examples/ui/display_and_visibility.rs
- examples/ui/text_debug.rs
- tests/window/minimizing.rs
- examples/window/scale_factor_override.rs
- examples/animation/morph_targets.rs
- examples/animation/animated_mesh_events.rs
- examples/app/logs.rs
- examples/remote/server.rs
- examples/diagnostics/custom_diagnostic.rs
- examples/games/loading_screen.rs
- examples/math/sampling_primitives.rs
- examples/games/game_menu.rs
- examples/3d/volumetric_fog.rs
- examples/3d/lightmaps.rs
- examples/math/cubic_splines.rs
- examples/2d/cpu_draw.rs
- examples/3d/depth_of_field.rs
- examples/ui/overflow_debug.rs
- examples/3d/anisotropy.rs
- examples/ui/ui_texture_atlas.rs
- examples/asset/extra_source.rs
- examples/3d/visibility_range.rs
- examples/3d/reflection_probes.rs
- examples/math/custom_primitives.rs
- examples/ui/viewport_debug.rs
- examples/ecs/generic_system.rs
- examples/3d/post_processing.rs
- examples/2d/sprite_animation.rs
- examples/window/custom_user_event.rs
- examples/testbed/2d.rs
- examples/testbed/3d.rs
- examples/animation/animation_masks.rs
- examples/3d/meshlet.rs
- examples/app/plugin_group.rs
- examples/3d/specular_tint.rs
- examples/3d/transmission.rs
- examples/ui/window_fallthrough.rs
- tests/window/resizing.rs
- examples/shader/custom_phase_item.rs
- examples/2d/custom_gltf_vertex_attribute.rs
- examples/stress_tests/text_pipeline.rs
- examples/ui/text_wrap_debug.rs
- examples/shader/shader_prepass.rs
- examples/testbed/ui.rs
- examples/3d/ssr.rs
- examples/animation/animation_graph.rs
- examples/math/bounding_2d.rs
- examples/stress_tests/many_lights.rs
- examples/window/transparent_window.rs
- examples/shader/compute_shader_game_of_life.rs
- examples/games/alien_cake_addict.rs
- examples/ecs/fallible_params.rs
- examples/stress_tests/many_text2d.rs
- examples/stress_tests/many_materials.rs
- examples/stress_tests/many_gizmos.rs
- examples/games/breakout.rs
- examples/3d/pcss.rs
- examples/ecs/system_piping.rs
- examples/stress_tests/many_glyphs.rs
- examples/3d/tonemapping.rs
- examples/picking/debug_picking.rs
- examples/state/custom_transitions.rs
- examples/camera/projection_zoom.rs
- examples/time/virtual_time.rs
- examples/asset/multi_asset_sync.rs
- examples/stress_tests/many_animated_sprites.rs
- examples/stress_tests/many_cubes.rs
- examples/dev_tools/fps_overlay.rs
- examples/3d/occlusion_culling.rs
- examples/stress_tests/many_sprites.rs
- examples/state/states.rs
- examples/app/headless.rs
- examples/3d/mixed_lighting.rs
- examples/3d/clustered_decals.rs
- examples/window/low_power.rs
- examples/state/sub_states.rs
- examples/games/desk_toy.rs
- examples/diagnostics/log_diagnostics.rs
- examples/3d/wireframe.rs
- examples/stress_tests/transform_hierarchy.rs
- examples/2d/wireframe_2d.rs
- examples/asset/processing/asset_processing.rs
- examples/movement/physics_in_fixed_timestep.rs
- examples/stress_tests/many_foxes.rs
- examples/app/headless_renderer.rs
- examples/math/render_primitives.rs
- examples/ecs/event.rs
- examples/stress_tests/bevymark.rs
- examples/ecs/observers.rs
- examples/ecs/system_closure.rs
- examples/ui/directional_navigation.rs
- examples/window/window_settings.rs
- examples/ecs/error_handling.rs
- examples/stress_tests/many_buttons.rs
- examples/3d/irradiance_volumes.rs
- examples/ecs/nondeterministic_system_order.rs
- examples/ecs/custom_schedule.rs
- examples/state/computed_states.rs
- examples/ecs/run_conditions.rs
- examples/stress_tests/many_components.rs
- examples/ecs/ecs_guide.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);
Examples found in repository?
More examples
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
.
Examples found in repository?
10fn my_runner(mut app: App) -> AppExit {
11 // Finalize plugin building, including running any necessary clean-up.
12 // This is normally completed by the default runner.
13 app.finish();
14 app.cleanup();
15
16 println!("Type stuff into the console");
17 for line in io::stdin().lines() {
18 {
19 let mut input = app.world_mut().resource_mut::<Input>();
20 input.0 = line.unwrap();
21 }
22 app.update();
23
24 if let Some(exit) = app.should_exit() {
25 return exit;
26 }
27 }
28
29 AppExit::Success
30}
More examples
14fn main() {
15 let mut app = App::new();
16 app.add_plugins(DefaultPlugins);
17
18 let main_app = app.main_mut();
19 configure_ambiguity_detection(main_app);
20 let render_extract_app = app.sub_app_mut(RenderExtractApp);
21 configure_ambiguity_detection(render_extract_app);
22
23 // Ambiguities in the RenderApp are currently allowed.
24 // Eventually, we should forbid these: see https://github.com/bevyengine/bevy/issues/7386
25 // Uncomment the lines below to show the current ambiguities in the RenderApp.
26 // let sub_app = app.sub_app_mut(bevy_render::RenderApp);
27 // configure_ambiguity_detection(sub_app);
28
29 app.finish();
30 app.cleanup();
31 app.update();
32
33 let main_app_ambiguities = count_ambiguities(app.main());
34 assert_eq!(
35 main_app_ambiguities.total(),
36 0,
37 "Main app has unexpected ambiguities among the following schedules: \n{main_app_ambiguities:#?}.",
38 );
39
40 // RenderApp is not checked here, because it is not within the App at this point.
41 let render_extract_ambiguities = count_ambiguities(app.sub_app(RenderExtractApp));
42 assert_eq!(
43 render_extract_ambiguities.total(),
44 0,
45 "RenderExtract app has unexpected ambiguities among the following schedules: \n{render_extract_ambiguities:#?}",
46 );
47}
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
.
Examples found in repository?
10fn my_runner(mut app: App) -> AppExit {
11 // Finalize plugin building, including running any necessary clean-up.
12 // This is normally completed by the default runner.
13 app.finish();
14 app.cleanup();
15
16 println!("Type stuff into the console");
17 for line in io::stdin().lines() {
18 {
19 let mut input = app.world_mut().resource_mut::<Input>();
20 input.0 = line.unwrap();
21 }
22 app.update();
23
24 if let Some(exit) = app.should_exit() {
25 return exit;
26 }
27 }
28
29 AppExit::Success
30}
More examples
14fn main() {
15 let mut app = App::new();
16 app.add_plugins(DefaultPlugins);
17
18 let main_app = app.main_mut();
19 configure_ambiguity_detection(main_app);
20 let render_extract_app = app.sub_app_mut(RenderExtractApp);
21 configure_ambiguity_detection(render_extract_app);
22
23 // Ambiguities in the RenderApp are currently allowed.
24 // Eventually, we should forbid these: see https://github.com/bevyengine/bevy/issues/7386
25 // Uncomment the lines below to show the current ambiguities in the RenderApp.
26 // let sub_app = app.sub_app_mut(bevy_render::RenderApp);
27 // configure_ambiguity_detection(sub_app);
28
29 app.finish();
30 app.cleanup();
31 app.update();
32
33 let main_app_ambiguities = count_ambiguities(app.main());
34 assert_eq!(
35 main_app_ambiguities.total(),
36 0,
37 "Main app has unexpected ambiguities among the following schedules: \n{main_app_ambiguities:#?}.",
38 );
39
40 // RenderApp is not checked here, because it is not within the App at this point.
41 let render_extract_ambiguities = count_ambiguities(app.sub_app(RenderExtractApp));
42 assert_eq!(
43 render_extract_ambiguities.total(),
44 0,
45 "RenderExtract app has unexpected ambiguities among the following schedules: \n{render_extract_ambiguities:#?}",
46 );
47}
Sourcepub fn add_systems<M>(
&mut self,
schedule: impl ScheduleLabel,
systems: impl IntoScheduleConfigs<Box<dyn System<Out = Result<(), BevyError>, In = ()>>, M>,
) -> &mut App
pub fn add_systems<M>( &mut self, schedule: impl ScheduleLabel, systems: impl IntoScheduleConfigs<Box<dyn System<Out = Result<(), BevyError>, In = ()>>, 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?
More examples
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 }
- examples/2d/sprite.rs
- examples/2d/sprite_flipping.rs
- examples/2d/sprite_slice.rs
- examples/2d/transparency_2d.rs
- examples/3d/3d_scene.rs
- examples/3d/orthographic.rs
- examples/3d/texture.rs
- examples/3d/two_passes.rs
- examples/3d/vertex_colors.rs
- examples/animation/eased_motion.rs
- examples/asset/asset_loading.rs
- examples/asset/hot_asset_reloading.rs
- examples/asset/repeated_texture.rs
- examples/audio/audio.rs
- examples/camera/custom_projection.rs
- examples/reflection/reflection_types.rs
- examples/ui/borders.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/ecs/startup_system.rs
- examples/input/char_input_events.rs
- examples/app/drag_and_drop.rs
- examples/input/mouse_input_events.rs
- examples/input/keyboard_input_events.rs
- examples/2d/mesh2d_manual.rs
- examples/asset/embedded_asset.rs
- examples/shader/custom_shader_instancing.rs
- examples/3d/decal.rs
- examples/shader/custom_render_phase.rs
- examples/asset/custom_asset_reader.rs
- examples/picking/simple_picking.rs
- examples/2d/mesh2d_repeated_texture.rs
- examples/input/mouse_input.rs
- examples/input/gamepad_input_events.rs
- examples/ecs/hierarchy.rs
- examples/2d/sprite_tile.rs
- examples/app/without_winit.rs
- examples/ecs/immutable_components.rs
- examples/transforms/translation.rs
- examples/3d/3d_viewport_to_world.rs
- examples/transforms/3d_rotation.rs
- examples/3d/generate_custom_mesh.rs
- examples/3d/lines.rs
- examples/3d/parenting.rs
- examples/animation/easing_functions.rs
- examples/stress_tests/many_cameras_lights.rs
- examples/ui/render_ui_to_texture.rs
- examples/2d/move_sprite.rs
- examples/shader/animate_shader.rs
- examples/shader/custom_vertex_attribute.rs
- examples/shader/shader_defs.rs
- examples/shader/shader_material.rs
- examples/shader/shader_material_glsl.rs
- examples/3d/animated_material.rs
- examples/3d/transparency_3d.rs
- examples/ecs/system_param.rs
- examples/ui/transparency_ui.rs
- examples/ui/z_index.rs
- examples/2d/bloom_2d.rs
- examples/3d/load_gltf_extras.rs
- examples/shader/specialized_mesh_pipeline.rs
- examples/3d/order_independent_transparency.rs
- examples/3d/query_gltf_primitives.rs
- examples/3d/pbr.rs
- examples/gizmos/axes.rs
- examples/math/random_sampling.rs
- examples/audio/audio_control.rs
- examples/ecs/parallel_query.rs
- examples/3d/camera_sub_view.rs
- examples/movement/smooth_follow.rs
- examples/transforms/scale.rs
- examples/3d/render_to_texture.rs
- examples/3d/rotate_environment_map.rs
- examples/3d/split_screen.rs
- examples/3d/blend_modes.rs
- examples/app/custom_loop.rs
- examples/async_tasks/async_compute.rs
- examples/window/screenshot.rs
- examples/3d/bloom_3d.rs
- examples/shader/custom_post_processing.rs
- examples/3d/atmosphere.rs
- examples/3d/edit_material_on_gltf.rs
- examples/shader/automatic_instancing.rs
- examples/shader/shader_material_2d.rs
- examples/shader/shader_material_bindless.rs
- examples/shader/storage_buffer.rs
- examples/gizmos/light_gizmos.rs
- examples/shader/fallback_image.rs
- examples/shader/shader_material_screenspace_texture.rs
- examples/app/log_layers.rs
- examples/3d/auto_exposure.rs
- examples/camera/camera_orbit.rs
- examples/3d/mesh_ray_cast.rs
- examples/3d/anti_aliasing.rs
- examples/ui/ghost_nodes.rs
- examples/audio/pitch.rs
- examples/time/timers.rs
- examples/3d/spherical_area_lights.rs
- examples/2d/sprite_sheet.rs
- examples/reflection/reflection.rs
- examples/ui/ui_material.rs
- examples/window/multiple_windows.rs
- examples/camera/2d_top_down_camera.rs
- examples/reflection/generic_reflection.rs
- examples/audio/soundtrack.rs
- examples/camera/2d_screen_shake.rs
- examples/picking/sprite_picking.rs
- examples/ui/text.rs
- examples/window/clear_color.rs
- examples/gizmos/2d_gizmos.rs
- examples/3d/update_gltf_scene.rs
- examples/2d/text2d.rs
- examples/3d/load_gltf.rs
- examples/ecs/component_hooks.rs
- examples/ui/size_constraints.rs
- examples/2d/pixel_grid_snap.rs
- examples/ui/scroll.rs
- examples/animation/animation_events.rs
- examples/3d/motion_blur.rs
- examples/audio/spatial_audio_3d.rs
- examples/2d/sprite_scale.rs
- examples/3d/atmospheric_fog.rs
- examples/asset/asset_decompression.rs
- examples/animation/animated_transform.rs
- examples/shader/array_texture.rs
- examples/gizmos/3d_gizmos.rs
- examples/picking/mesh_picking.rs
- examples/animation/animated_ui.rs
- examples/shader/texture_binding_array.rs
- examples/transforms/align.rs
- examples/animation/gltf_skinned_mesh.rs
- examples/animation/custom_skinned_mesh.rs
- examples/shader/shader_material_wesl.rs
- examples/ui/box_shadow.rs
- examples/ui/overflow_clip_margin.rs
- examples/ui/font_atlas_debug.rs
- examples/window/monitor_info.rs
- examples/testbed/full_ui.rs
- examples/shader/extended_material.rs
- examples/2d/2d_viewport_to_world.rs
- examples/3d/spotlight.rs
- examples/ecs/iter_combinations.rs
- examples/3d/ssao.rs
- examples/2d/mesh2d_arcs.rs
- examples/3d/fog.rs
- examples/shader/extended_material_bindless.rs
- examples/app/plugin.rs
- examples/audio/decodable.rs
- examples/2d/2d_shapes.rs
- examples/async_tasks/external_source_external_thread.rs
- examples/ui/button.rs
- examples/ui/ui_texture_atlas_slice.rs
- examples/ui/ui_texture_slice.rs
- examples/ui/overflow.rs
- examples/3d/clearcoat.rs
- examples/diagnostics/enabling_disabling_diagnostic.rs
- examples/ui/ui_texture_slice_flip_and_tile.rs
- examples/audio/spatial_audio_2d.rs
- examples/ui/relative_cursor_position.rs
- examples/animation/animated_mesh.rs
- examples/ecs/change_detection.rs
- examples/ecs/entity_disabling.rs
- examples/ecs/removal_detection.rs
- examples/input/text_input.rs
- examples/camera/first_person_view_model.rs
- examples/ui/flex_layout.rs
- examples/shader/gpu_readback.rs
- examples/transforms/transform.rs
- examples/ecs/custom_query_param.rs
- examples/animation/animated_mesh_control.rs
- examples/asset/asset_settings.rs
- examples/asset/custom_asset.rs
- examples/games/contributors.rs
- examples/3d/parallax_mapping.rs
- examples/asset/alter_mesh.rs
- examples/asset/alter_sprite.rs
- examples/ui/tab_navigation.rs
- examples/scene/scene.rs
- examples/2d/rotation.rs
- examples/3d/skybox.rs
- examples/2d/texture_atlas.rs
- examples/ui/grid.rs
- examples/3d/deferred_rendering.rs
- examples/ecs/observer_propagation.rs
- examples/3d/color_grading.rs
- examples/window/window_resizing.rs
- examples/3d/fog_volumes.rs
- examples/time/time.rs
- examples/3d/lighting.rs
- examples/ecs/one_shot_systems.rs
- examples/ui/ui_scaling.rs
- examples/3d/shadow_biases.rs
- examples/animation/color_animation.rs
- examples/app/return_after_run.rs
- examples/window/custom_cursor_image.rs
- examples/app/log_layers_ecs.rs
- examples/window/window_drag_move.rs
- examples/ecs/fixed_timestep.rs
- examples/3d/3d_shapes.rs
- examples/3d/scrolling_fog.rs
- examples/3d/shadow_caster_receiver.rs
- examples/ui/display_and_visibility.rs
- examples/ui/text_debug.rs
- tests/window/minimizing.rs
- examples/window/scale_factor_override.rs
- examples/animation/morph_targets.rs
- examples/animation/animated_mesh_events.rs
- examples/app/logs.rs
- examples/remote/server.rs
- examples/diagnostics/custom_diagnostic.rs
- examples/games/loading_screen.rs
- examples/math/sampling_primitives.rs
- examples/games/game_menu.rs
- examples/3d/volumetric_fog.rs
- examples/3d/lightmaps.rs
- examples/math/cubic_splines.rs
- examples/2d/cpu_draw.rs
- examples/3d/depth_of_field.rs
- examples/ui/overflow_debug.rs
- examples/3d/anisotropy.rs
- examples/ui/ui_texture_atlas.rs
- examples/asset/extra_source.rs
- examples/3d/visibility_range.rs
- examples/3d/reflection_probes.rs
- examples/math/custom_primitives.rs
- examples/ui/viewport_debug.rs
- examples/ecs/generic_system.rs
- examples/3d/post_processing.rs
- examples/2d/sprite_animation.rs
- examples/window/custom_user_event.rs
- examples/testbed/2d.rs
- examples/testbed/3d.rs
- examples/animation/animation_masks.rs
- examples/3d/meshlet.rs
- examples/3d/specular_tint.rs
- examples/3d/transmission.rs
- examples/ui/window_fallthrough.rs
- tests/window/resizing.rs
- examples/shader/custom_phase_item.rs
- examples/2d/custom_gltf_vertex_attribute.rs
- examples/stress_tests/text_pipeline.rs
- examples/ecs/send_and_receive_events.rs
- examples/ui/text_wrap_debug.rs
- examples/shader/shader_prepass.rs
- examples/testbed/ui.rs
- examples/3d/ssr.rs
- examples/animation/animation_graph.rs
- examples/math/bounding_2d.rs
- examples/stress_tests/many_lights.rs
- examples/window/transparent_window.rs
- examples/shader/compute_shader_game_of_life.rs
- examples/games/alien_cake_addict.rs
- examples/ecs/fallible_params.rs
- examples/stress_tests/many_text2d.rs
- examples/stress_tests/many_materials.rs
- examples/stress_tests/many_gizmos.rs
- examples/games/breakout.rs
- examples/3d/pcss.rs
- examples/ecs/system_piping.rs
- examples/stress_tests/many_glyphs.rs
- examples/3d/tonemapping.rs
- examples/picking/debug_picking.rs
- examples/state/custom_transitions.rs
- examples/camera/projection_zoom.rs
- examples/time/virtual_time.rs
- examples/asset/multi_asset_sync.rs
- examples/stress_tests/many_animated_sprites.rs
- examples/stress_tests/many_cubes.rs
- examples/dev_tools/fps_overlay.rs
- examples/3d/occlusion_culling.rs
- examples/stress_tests/many_sprites.rs
- examples/state/states.rs
- examples/app/headless.rs
- examples/3d/mixed_lighting.rs
- examples/3d/clustered_decals.rs
- examples/window/low_power.rs
- examples/games/stepping.rs
- examples/state/sub_states.rs
- examples/games/desk_toy.rs
- examples/diagnostics/log_diagnostics.rs
- examples/3d/wireframe.rs
- examples/stress_tests/transform_hierarchy.rs
- examples/2d/wireframe_2d.rs
- examples/asset/processing/asset_processing.rs
- examples/movement/physics_in_fixed_timestep.rs
- examples/stress_tests/many_foxes.rs
- examples/app/headless_renderer.rs
- examples/math/render_primitives.rs
- examples/ecs/event.rs
- examples/stress_tests/bevymark.rs
- examples/ecs/observers.rs
- examples/ecs/system_closure.rs
- examples/ui/directional_navigation.rs
- examples/window/window_settings.rs
- examples/ecs/error_handling.rs
- examples/stress_tests/many_buttons.rs
- examples/3d/irradiance_volumes.rs
- examples/ecs/nondeterministic_system_order.rs
- examples/ecs/custom_schedule.rs
- examples/state/computed_states.rs
- examples/ecs/run_conditions.rs
- examples/ecs/ecs_guide.rs
- examples/ecs/system_stepping.rs
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.
Examples found in repository?
293fn main() {
294 // Bevy apps are created using the builder pattern. We use the builder to add systems,
295 // resources, and plugins to our app
296 App::new()
297 // Resources that implement the Default or FromWorld trait can be added like this:
298 .init_resource::<GameState>()
299 // Plugins are just a grouped set of app builder calls (just like we're doing here).
300 // We could easily turn our game into a plugin, but you can check out the plugin example for
301 // that :) The plugin below runs our app's "system schedule" once every 5 seconds.
302 .add_plugins(ScheduleRunnerPlugin::run_loop(Duration::from_secs(5)))
303 // `Startup` systems run exactly once BEFORE all other systems. These are generally used for
304 // app initialization code (ex: adding entities and resources)
305 .add_systems(Startup, startup_system)
306 // `Update` systems run once every update. These are generally used for "real-time app logic"
307 .add_systems(Update, print_message_system)
308 // SYSTEM EXECUTION ORDER
309 //
310 // Each system belongs to a `Schedule`, which controls the execution strategy and broad order
311 // of the systems within each tick. The `Startup` schedule holds
312 // startup systems, which are run a single time before `Update` runs. `Update` runs once per app update,
313 // which is generally one "frame" or one "tick".
314 //
315 // By default, all systems in a `Schedule` run in parallel, except when they require mutable access to a
316 // piece of data. This is efficient, but sometimes order matters.
317 // For example, we want our "game over" system to execute after all other systems to ensure
318 // we don't accidentally run the game for an extra round.
319 //
320 // You can force an explicit ordering between systems using the `.before` or `.after` methods.
321 // Systems will not be scheduled until all of the systems that they have an "ordering dependency" on have
322 // completed.
323 // There are other schedules, such as `Last` which runs at the very end of each run.
324 .add_systems(Last, print_at_end_round)
325 // We can also create new system sets, and order them relative to other system sets.
326 // Here is what our games execution order will look like:
327 // "before_round": new_player_system, new_round_system
328 // "round": print_message_system, score_system
329 // "after_round": score_check_system, game_over_system
330 .configure_sets(
331 Update,
332 // chain() will ensure sets run in the order they are listed
333 (MySet::BeforeRound, MySet::Round, MySet::AfterRound).chain(),
334 )
335 // The add_systems function is powerful. You can define complex system configurations with ease!
336 .add_systems(
337 Update,
338 (
339 // These `BeforeRound` systems will run before `Round` systems, thanks to the chained set configuration
340 (
341 // You can also chain systems! new_round_system will run first, followed by new_player_system
342 (new_round_system, new_player_system).chain(),
343 exclusive_player_system,
344 )
345 // All of the systems in the tuple above will be added to this set
346 .in_set(MySet::BeforeRound),
347 // This `Round` system will run after the `BeforeRound` systems thanks to the chained set configuration
348 score_system.in_set(MySet::Round),
349 // These `AfterRound` systems will run after the `Round` systems thanks to the chained set configuration
350 (
351 score_check_system,
352 // In addition to chain(), you can also use `before(system)` and `after(system)`. This also works
353 // with sets!
354 game_over_system.after(score_check_system),
355 )
356 .in_set(MySet::AfterRound),
357 ),
358 )
359 // This call to run() starts the app we just built!
360 .run();
361}
Sourcepub fn add_event<T>(&mut self) -> &mut Appwhere
T: Event,
pub fn add_event<T>(&mut self) -> &mut Appwhere
T: Event,
Initializes T
event handling by inserting an event queue resource (Events::<T>
)
and scheduling an event_update_system
in First
.
See Events
for information on how to define events.
§Examples
app.add_event::<MyEvent>();
Examples found in repository?
More examples
99fn custom_layer(app: &mut App) -> Option<BoxedLayer> {
100 let (sender, receiver) = mpsc::channel();
101
102 let layer = CaptureLayer { sender };
103 let resource = CapturedLogEvents(receiver);
104
105 app.insert_non_send_resource(resource);
106 app.add_event::<LogEvent>();
107 app.add_systems(Update, transfer_log_events);
108
109 Some(layer.boxed())
110}
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
- examples/3d/spherical_area_lights.rs
- examples/window/clear_color.rs
- examples/3d/update_gltf_scene.rs
- examples/shader/shader_material_wesl.rs
- examples/3d/load_gltf.rs
- examples/ui/scroll.rs
- examples/animation/animated_transform.rs
- examples/animation/gltf_skinned_mesh.rs
- examples/animation/custom_skinned_mesh.rs
- examples/ui/box_shadow.rs
- examples/ui/overflow_clip_margin.rs
- examples/ui/font_atlas_debug.rs
- examples/3d/spotlight.rs
- examples/ecs/iter_combinations.rs
- examples/3d/ssao.rs
- examples/3d/fog.rs
- examples/app/plugin.rs
- examples/async_tasks/external_source_external_thread.rs
- examples/ui/button.rs
- examples/ui/ui_texture_atlas_slice.rs
- examples/ui/ui_texture_slice.rs
- examples/ui/overflow.rs
- examples/ui/ui_texture_slice_flip_and_tile.rs
- examples/ui/relative_cursor_position.rs
- examples/animation/animated_mesh.rs
- examples/shader/gpu_readback.rs
- examples/animation/animated_mesh_control.rs
- examples/ui/tab_navigation.rs
- examples/2d/rotation.rs
- examples/3d/deferred_rendering.rs
- examples/window/window_resizing.rs
- examples/3d/fog_volumes.rs
- examples/time/time.rs
- examples/3d/lighting.rs
- examples/ui/ui_scaling.rs
- examples/window/window_drag_move.rs
- examples/ecs/fixed_timestep.rs
- examples/3d/scrolling_fog.rs
- examples/ui/display_and_visibility.rs
- examples/animation/morph_targets.rs
- examples/animation/animated_mesh_events.rs
- examples/games/loading_screen.rs
- examples/math/sampling_primitives.rs
- examples/games/game_menu.rs
- examples/3d/volumetric_fog.rs
- examples/3d/lightmaps.rs
- examples/2d/cpu_draw.rs
- examples/ui/ui_texture_atlas.rs
- examples/ui/viewport_debug.rs
- examples/animation/animation_masks.rs
- examples/3d/meshlet.rs
- examples/3d/specular_tint.rs
- examples/3d/transmission.rs
- examples/ui/window_fallthrough.rs
- tests/window/resizing.rs
- examples/2d/custom_gltf_vertex_attribute.rs
- examples/stress_tests/text_pipeline.rs
- examples/ui/text_wrap_debug.rs
- examples/3d/ssr.rs
- examples/animation/animation_graph.rs
- examples/stress_tests/many_lights.rs
- examples/window/transparent_window.rs
- examples/shader/compute_shader_game_of_life.rs
- examples/3d/occlusion_culling.rs
- examples/games/alien_cake_addict.rs
- examples/stress_tests/many_text2d.rs
- examples/stress_tests/many_materials.rs
- examples/stress_tests/many_gizmos.rs
- examples/games/breakout.rs
- examples/ecs/system_piping.rs
- examples/stress_tests/many_glyphs.rs
- examples/3d/tonemapping.rs
- examples/picking/debug_picking.rs
- examples/camera/projection_zoom.rs
- examples/asset/multi_asset_sync.rs
- examples/stress_tests/many_animated_sprites.rs
- examples/stress_tests/many_cubes.rs
- examples/stress_tests/many_sprites.rs
- examples/3d/mixed_lighting.rs
- examples/window/low_power.rs
- examples/games/stepping.rs
- examples/games/desk_toy.rs
- examples/3d/wireframe.rs
- examples/stress_tests/transform_hierarchy.rs
- examples/2d/wireframe_2d.rs
- examples/stress_tests/many_foxes.rs
- examples/app/headless_renderer.rs
- examples/stress_tests/bevymark.rs
- examples/ui/directional_navigation.rs
- examples/stress_tests/many_buttons.rs
- examples/3d/irradiance_volumes.rs
- examples/ecs/system_stepping.rs
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>();
Examples found in repository?
More examples
92fn main() {
93 App::new()
94 .add_plugins(DefaultPlugins)
95 .init_resource::<State>()
96 .init_asset::<CustomAsset>()
97 .init_asset::<Blob>()
98 .init_asset_loader::<CustomAssetLoader>()
99 .init_asset_loader::<BlobAssetLoader>()
100 .add_systems(Startup, setup)
101 .add_systems(Update, print_on_load)
102 .run();
103}
- examples/games/contributors.rs
- examples/3d/color_grading.rs
- examples/animation/animated_mesh_events.rs
- examples/3d/volumetric_fog.rs
- examples/3d/depth_of_field.rs
- examples/ui/overflow_debug.rs
- examples/3d/anisotropy.rs
- examples/3d/visibility_range.rs
- examples/3d/reflection_probes.rs
- examples/3d/post_processing.rs
- examples/animation/animation_masks.rs
- examples/3d/specular_tint.rs
- examples/3d/ssr.rs
- examples/games/alien_cake_addict.rs
- examples/stress_tests/many_text2d.rs
- examples/3d/pcss.rs
- examples/3d/tonemapping.rs
- examples/3d/occlusion_culling.rs
- examples/3d/mixed_lighting.rs
- examples/3d/clustered_decals.rs
- examples/app/headless_renderer.rs
- examples/ecs/event.rs
- examples/ecs/observers.rs
- examples/ui/directional_navigation.rs
- examples/3d/irradiance_volumes.rs
- examples/ecs/nondeterministic_system_order.rs
- examples/ecs/run_conditions.rs
- examples/ecs/ecs_guide.rs
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 });
Examples found in repository?
99fn custom_layer(app: &mut App) -> Option<BoxedLayer> {
100 let (sender, receiver) = mpsc::channel();
101
102 let layer = CaptureLayer { sender };
103 let resource = CapturedLogEvents(receiver);
104
105 app.insert_non_send_resource(resource);
106 app.add_event::<LogEvent>();
107 app.add_systems(Update, transfer_log_events);
108
109 Some(layer.boxed())
110}
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.
Plugin
s can be grouped into a set by using a PluginGroup
.
There are built-in PluginGroup
s that provide core engine functionality.
The PluginGroup
s 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 Plugin
s by using a tuple over Plugin
s and
PluginGroup
s. 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/2d/sprite_slice.rs
- examples/2d/transparency_2d.rs
- examples/3d/3d_scene.rs
- examples/3d/orthographic.rs
- examples/3d/texture.rs
- examples/3d/two_passes.rs
- examples/3d/vertex_colors.rs
- examples/animation/eased_motion.rs
- examples/asset/asset_loading.rs
- examples/asset/hot_asset_reloading.rs
- examples/asset/repeated_texture.rs
- examples/audio/audio.rs
- examples/camera/custom_projection.rs
- examples/reflection/reflection_types.rs
- examples/ui/borders.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/input/char_input_events.rs
- examples/app/drag_and_drop.rs
- examples/input/mouse_input_events.rs
- examples/input/keyboard_input_events.rs
- examples/2d/mesh2d_manual.rs
- examples/asset/embedded_asset.rs
- examples/shader/custom_shader_instancing.rs
- examples/3d/decal.rs
- examples/shader/custom_render_phase.rs
- examples/asset/custom_asset_reader.rs
- examples/picking/simple_picking.rs
- examples/2d/mesh2d_repeated_texture.rs
- examples/input/mouse_input.rs
- examples/input/gamepad_input_events.rs
- examples/ecs/hierarchy.rs
- examples/2d/sprite_tile.rs
- examples/app/without_winit.rs
- examples/transforms/translation.rs
- examples/3d/3d_viewport_to_world.rs
- examples/transforms/3d_rotation.rs
- examples/3d/generate_custom_mesh.rs
- examples/3d/lines.rs
- examples/3d/parenting.rs
- examples/animation/easing_functions.rs
- examples/stress_tests/many_cameras_lights.rs
- examples/ui/render_ui_to_texture.rs
- examples/2d/move_sprite.rs
- examples/shader/animate_shader.rs
- examples/shader/custom_vertex_attribute.rs
- examples/shader/shader_defs.rs
- examples/shader/shader_material.rs
- examples/shader/shader_material_glsl.rs
- examples/3d/animated_material.rs
- examples/3d/transparency_3d.rs
- tests/3d/no_prepass.rs
- examples/ui/transparency_ui.rs
- examples/ui/z_index.rs
- examples/2d/bloom_2d.rs
- examples/3d/load_gltf_extras.rs
- examples/shader/specialized_mesh_pipeline.rs
- examples/3d/order_independent_transparency.rs
- examples/3d/query_gltf_primitives.rs
- examples/3d/pbr.rs
- examples/gizmos/axes.rs
- examples/math/random_sampling.rs
- examples/app/thread_pool_resources.rs
- examples/audio/audio_control.rs
- examples/ecs/parallel_query.rs
- examples/3d/camera_sub_view.rs
- examples/movement/smooth_follow.rs
- examples/transforms/scale.rs
- examples/3d/render_to_texture.rs
- examples/3d/rotate_environment_map.rs
- examples/3d/split_screen.rs
- examples/3d/blend_modes.rs
- examples/async_tasks/async_compute.rs
- examples/window/screenshot.rs
- examples/3d/bloom_3d.rs
- examples/shader/custom_post_processing.rs
- examples/3d/atmosphere.rs
- examples/3d/edit_material_on_gltf.rs
- examples/shader/automatic_instancing.rs
- examples/shader/shader_material_2d.rs
- examples/shader/shader_material_bindless.rs
- examples/shader/storage_buffer.rs
- examples/gizmos/light_gizmos.rs
- examples/shader/fallback_image.rs
- examples/shader/shader_material_screenspace_texture.rs
- examples/app/log_layers.rs
- examples/3d/auto_exposure.rs
- examples/camera/camera_orbit.rs
- examples/3d/mesh_ray_cast.rs
- examples/3d/anti_aliasing.rs
- examples/ui/ghost_nodes.rs
- examples/audio/pitch.rs
- examples/time/timers.rs
- examples/3d/spherical_area_lights.rs
- examples/2d/sprite_sheet.rs
- examples/reflection/reflection.rs
- examples/ui/ui_material.rs
- examples/window/multiple_windows.rs
- examples/camera/2d_top_down_camera.rs
- examples/reflection/generic_reflection.rs
- examples/audio/soundtrack.rs
- examples/camera/2d_screen_shake.rs
- examples/picking/sprite_picking.rs
- examples/ui/text.rs
- examples/window/clear_color.rs
- examples/gizmos/2d_gizmos.rs
- examples/3d/update_gltf_scene.rs
- examples/2d/text2d.rs
- examples/3d/load_gltf.rs
- examples/ecs/component_hooks.rs
- examples/ui/size_constraints.rs
- examples/2d/pixel_grid_snap.rs
- examples/ui/scroll.rs
- examples/animation/animation_events.rs
- examples/3d/motion_blur.rs
- examples/audio/spatial_audio_3d.rs
- examples/2d/sprite_scale.rs
- examples/3d/atmospheric_fog.rs
- examples/asset/asset_decompression.rs
- examples/animation/animated_transform.rs
- examples/shader/array_texture.rs
- examples/gizmos/3d_gizmos.rs
- examples/picking/mesh_picking.rs
- examples/animation/animated_ui.rs
- examples/shader/texture_binding_array.rs
- examples/transforms/align.rs
- examples/animation/gltf_skinned_mesh.rs
- examples/animation/custom_skinned_mesh.rs
- examples/shader/shader_material_wesl.rs
- examples/ui/box_shadow.rs
- examples/ui/overflow_clip_margin.rs
- examples/ui/font_atlas_debug.rs
- examples/window/monitor_info.rs
- examples/testbed/full_ui.rs
- examples/shader/extended_material.rs
- examples/2d/2d_viewport_to_world.rs
- examples/3d/spotlight.rs
- examples/ecs/iter_combinations.rs
- examples/3d/ssao.rs
- examples/2d/mesh2d_arcs.rs
- examples/3d/fog.rs
- examples/shader/extended_material_bindless.rs
- examples/audio/decodable.rs
- examples/2d/2d_shapes.rs
- examples/async_tasks/external_source_external_thread.rs
- examples/ui/button.rs
- examples/ui/ui_texture_atlas_slice.rs
- examples/ui/ui_texture_slice.rs
- examples/ui/overflow.rs
- examples/3d/clearcoat.rs
- examples/diagnostics/enabling_disabling_diagnostic.rs
- examples/app/no_renderer.rs
- examples/ui/ui_texture_slice_flip_and_tile.rs
- examples/audio/spatial_audio_2d.rs
- examples/ui/relative_cursor_position.rs
- examples/animation/animated_mesh.rs
- examples/ecs/change_detection.rs
- examples/ecs/entity_disabling.rs
- examples/ecs/removal_detection.rs
- examples/input/text_input.rs
- examples/camera/first_person_view_model.rs
- examples/ui/flex_layout.rs
- examples/app/plugin.rs
- examples/shader/gpu_readback.rs
- examples/transforms/transform.rs
- examples/animation/animated_mesh_control.rs
- examples/asset/asset_settings.rs
- examples/asset/custom_asset.rs
- examples/games/contributors.rs
- examples/3d/parallax_mapping.rs
- examples/asset/alter_mesh.rs
- examples/asset/alter_sprite.rs
- examples/ui/tab_navigation.rs
- examples/scene/scene.rs
- examples/2d/rotation.rs
- examples/3d/skybox.rs
- examples/2d/texture_atlas.rs
- examples/ui/grid.rs
- examples/3d/deferred_rendering.rs
- examples/ecs/observer_propagation.rs
- examples/3d/color_grading.rs
- examples/window/window_resizing.rs
- examples/3d/fog_volumes.rs
- examples/time/time.rs
- examples/3d/lighting.rs
- examples/ecs/one_shot_systems.rs
- examples/ui/ui_scaling.rs
- examples/3d/shadow_biases.rs
- examples/animation/color_animation.rs
- examples/app/return_after_run.rs
- examples/window/custom_cursor_image.rs
- examples/app/log_layers_ecs.rs
- examples/window/window_drag_move.rs
- examples/ecs/fixed_timestep.rs
- examples/3d/3d_shapes.rs
- examples/3d/scrolling_fog.rs
- examples/3d/shadow_caster_receiver.rs
- examples/ui/display_and_visibility.rs
- examples/ui/text_debug.rs
- tests/window/minimizing.rs
- examples/window/scale_factor_override.rs
- examples/animation/morph_targets.rs
- examples/animation/animated_mesh_events.rs
- examples/app/logs.rs
- examples/remote/server.rs
- examples/diagnostics/custom_diagnostic.rs
- examples/games/loading_screen.rs
- examples/math/sampling_primitives.rs
- examples/games/game_menu.rs
- examples/3d/volumetric_fog.rs
- examples/3d/lightmaps.rs
- examples/math/cubic_splines.rs
- examples/2d/cpu_draw.rs
- examples/3d/depth_of_field.rs
- examples/ui/overflow_debug.rs
- examples/3d/anisotropy.rs
- examples/ui/ui_texture_atlas.rs
- examples/asset/extra_source.rs
- examples/3d/visibility_range.rs
- examples/3d/reflection_probes.rs
- examples/math/custom_primitives.rs
- examples/ui/viewport_debug.rs
- examples/ecs/generic_system.rs
- examples/3d/post_processing.rs
- examples/2d/sprite_animation.rs
- examples/window/custom_user_event.rs
- examples/testbed/2d.rs
- examples/testbed/3d.rs
- examples/animation/animation_masks.rs
- examples/3d/meshlet.rs
- examples/app/plugin_group.rs
- examples/3d/specular_tint.rs
- examples/3d/transmission.rs
- examples/ui/window_fallthrough.rs
- tests/window/resizing.rs
- examples/shader/custom_phase_item.rs
- examples/2d/custom_gltf_vertex_attribute.rs
- examples/stress_tests/text_pipeline.rs
- examples/ecs/send_and_receive_events.rs
- examples/ui/text_wrap_debug.rs
- examples/shader/shader_prepass.rs
- examples/testbed/ui.rs
- examples/3d/ssr.rs
- examples/animation/animation_graph.rs
- examples/math/bounding_2d.rs
- examples/stress_tests/many_lights.rs
- examples/window/transparent_window.rs
- examples/shader/compute_shader_game_of_life.rs
- examples/games/alien_cake_addict.rs
- examples/ecs/fallible_params.rs
- examples/stress_tests/many_text2d.rs
- examples/stress_tests/many_materials.rs
- examples/stress_tests/many_gizmos.rs
- examples/games/breakout.rs
- examples/3d/pcss.rs
- examples/ecs/system_piping.rs
- examples/stress_tests/many_glyphs.rs
- examples/3d/tonemapping.rs
- examples/picking/debug_picking.rs
- examples/state/custom_transitions.rs
- examples/camera/projection_zoom.rs
- examples/time/virtual_time.rs
- examples/asset/multi_asset_sync.rs
- examples/stress_tests/many_animated_sprites.rs
- examples/stress_tests/many_cubes.rs
- examples/dev_tools/fps_overlay.rs
- examples/3d/occlusion_culling.rs
- examples/stress_tests/many_sprites.rs
- examples/state/states.rs
- examples/app/headless.rs
- examples/3d/mixed_lighting.rs
- examples/3d/clustered_decals.rs
- examples/window/low_power.rs
- examples/state/sub_states.rs
- examples/games/desk_toy.rs
- examples/diagnostics/log_diagnostics.rs
- examples/3d/wireframe.rs
- tests/ecs/ambiguity_detection.rs
- examples/stress_tests/transform_hierarchy.rs
- examples/2d/wireframe_2d.rs
- examples/asset/processing/asset_processing.rs
- examples/movement/physics_in_fixed_timestep.rs
- examples/stress_tests/many_foxes.rs
- examples/app/headless_renderer.rs
- examples/math/render_primitives.rs
- examples/ecs/event.rs
- examples/stress_tests/bevymark.rs
- examples/ecs/observers.rs
- examples/ecs/system_closure.rs
- examples/ui/directional_navigation.rs
- examples/window/window_settings.rs
- examples/ecs/error_handling.rs
- examples/stress_tests/many_buttons.rs
- examples/3d/irradiance_volumes.rs
- examples/ecs/nondeterministic_system_order.rs
- examples/state/computed_states.rs
- examples/ecs/run_conditions.rs
- examples/stress_tests/many_components.rs
- examples/ecs/ecs_guide.rs
- examples/ecs/system_stepping.rs
Sourcepub fn register_type<T>(&mut self) -> &mut Appwhere
T: GetTypeRegistration,
pub fn register_type<T>(&mut self) -> &mut Appwhere
T: GetTypeRegistration,
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, ReflectDeserialize
See bevy_reflect::TypeRegistry::register
for more information.
Examples found in repository?
More examples
35fn main() {
36 App::new()
37 .add_plugins(DefaultPlugins)
38 .register_type::<ComponentA>()
39 .register_type::<ComponentB>()
40 .register_type::<ResourceA>()
41 .add_systems(
42 Startup,
43 (save_scene_system, load_scene_system, infotext_system),
44 )
45 .add_systems(Update, (log_system, panic_on_fail))
46 .run();
47}
11fn main() {
12 App::new()
13 .add_plugins(DefaultPlugins)
14 .add_plugins(RemotePlugin::default())
15 .add_plugins(RemoteHttpPlugin::default())
16 .add_systems(Startup, setup)
17 .add_systems(Update, remove.run_if(input_just_pressed(KeyCode::Space)))
18 .add_systems(Update, move_cube)
19 // New types must be registered in order to be usable with reflection.
20 .register_type::<Cube>()
21 .register_type::<TestResource>()
22 .run();
23}
Sourcepub fn register_type_data<T, D>(&mut self) -> &mut App
pub fn register_type_data<T, D>(&mut self) -> &mut App
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,
pub fn register_function<F, Marker>(&mut self, function: F) -> &mut Appwhere
F: IntoFunction<'static, Marker> + 'static,
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,
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,
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
10fn my_runner(mut app: App) -> AppExit {
11 // Finalize plugin building, including running any necessary clean-up.
12 // This is normally completed by the default runner.
13 app.finish();
14 app.cleanup();
15
16 println!("Type stuff into the console");
17 for line in io::stdin().lines() {
18 {
19 let mut input = app.world_mut().resource_mut::<Input>();
20 input.0 = line.unwrap();
21 }
22 app.update();
23
24 if let Some(exit) = app.should_exit() {
25 return exit;
26 }
27 }
28
29 AppExit::Success
30}
248 fn finish(&self, app: &mut App) {
249 // Create the `SavedIndirectParameters` resource that we're going to use
250 // to communicate between the thread that the GPU-to-CPU readback
251 // callback runs on and the main application threads. This resource is
252 // atomically reference counted. We store one reference to the
253 // `SavedIndirectParameters` in the main app and another reference in
254 // the render app.
255 let saved_indirect_parameters = SavedIndirectParameters::from_world(app.world_mut());
256 app.insert_resource(saved_indirect_parameters.clone());
257
258 // Fetch the render app.
259 let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
260 return;
261 };
262
263 render_app
264 // Insert another reference to the `SavedIndirectParameters`.
265 .insert_resource(saved_indirect_parameters);
266 }
297 fn build(&self, app: &mut App) {
298 // Load our custom shader
299 let mut shaders = app.world_mut().resource_mut::<Assets<Shader>>();
300 shaders.insert(
301 &COLORED_MESH2D_SHADER_HANDLE,
302 Shader::from_wgsl(COLORED_MESH2D_SHADER, file!()),
303 );
304 app.add_plugins(SyncComponentPlugin::<ColoredMesh2d>::default());
305
306 // Register our custom draw function, and add our render systems
307 app.get_sub_app_mut(RenderApp)
308 .unwrap()
309 .add_render_command::<Transparent2d, DrawColoredMesh2d>()
310 .init_resource::<SpecializedRenderPipelines<ColoredMesh2dPipeline>>()
311 .init_resource::<RenderColoredMesh2dInstances>()
312 .add_systems(
313 ExtractSchedule,
314 extract_colored_mesh2d.after(extract_mesh2d),
315 )
316 .add_systems(Render, queue_colored_mesh2d.in_set(RenderSet::QueueMeshes));
317 }
34 fn build(&self, app: &mut App) {
35 app.add_systems(Startup, build_stepping_hint);
36 if cfg!(not(feature = "bevy_debug_stepping")) {
37 return;
38 }
39
40 // create and insert our debug schedule into the main schedule order.
41 // We need an independent schedule so we have access to all other
42 // schedules through the `Stepping` resource
43 app.init_schedule(DebugSchedule);
44 let mut order = app.world_mut().resource_mut::<MainScheduleOrder>();
45 order.insert_after(Update, DebugSchedule);
46
47 // create our stepping resource
48 let mut stepping = Stepping::new();
49 for label in &self.schedule_labels {
50 stepping.add_schedule(*label);
51 }
52 app.insert_resource(stepping);
53
54 // add our startup & stepping systems
55 app.insert_resource(State {
56 ui_top: self.top,
57 ui_left: self.left,
58 systems: Vec::new(),
59 })
60 .add_systems(
61 DebugSchedule,
62 (
63 build_ui.run_if(not(initialized)),
64 handle_input,
65 update_ui.run_if(initialized),
66 )
67 .chain(),
68 );
69 }
35fn runner(mut app: App) -> AppExit {
36 banner();
37 help();
38 let stdin = io::stdin();
39 for line in stdin.lock().lines() {
40 if let Err(err) = line {
41 println!("read err: {err:#}");
42 break;
43 }
44 match line.unwrap().as_str() {
45 "" => {
46 app.update();
47 }
48 "f" => {
49 println!("FAST: setting relative speed to 2x");
50 app.world_mut()
51 .resource_mut::<Time<Virtual>>()
52 .set_relative_speed(2.0);
53 }
54 "n" => {
55 println!("NORMAL: setting relative speed to 1x");
56 app.world_mut()
57 .resource_mut::<Time<Virtual>>()
58 .set_relative_speed(1.0);
59 }
60 "s" => {
61 println!("SLOW: setting relative speed to 0.5x");
62 app.world_mut()
63 .resource_mut::<Time<Virtual>>()
64 .set_relative_speed(0.5);
65 }
66 "p" => {
67 println!("PAUSE: pausing virtual clock");
68 app.world_mut().resource_mut::<Time<Virtual>>().pause();
69 }
70 "u" => {
71 println!("UNPAUSE: resuming virtual clock");
72 app.world_mut().resource_mut::<Time<Virtual>>().unpause();
73 }
74 "q" => {
75 println!("QUITTING!");
76 break;
77 }
78 _ => {
79 help();
80 }
81 }
82 }
83
84 AppExit::Success
85}
Sourcepub fn main(&self) -> &SubApp
pub fn main(&self) -> &SubApp
Returns a reference to the main SubApp
.
Examples found in repository?
14fn main() {
15 let mut app = App::new();
16 app.add_plugins(DefaultPlugins);
17
18 let main_app = app.main_mut();
19 configure_ambiguity_detection(main_app);
20 let render_extract_app = app.sub_app_mut(RenderExtractApp);
21 configure_ambiguity_detection(render_extract_app);
22
23 // Ambiguities in the RenderApp are currently allowed.
24 // Eventually, we should forbid these: see https://github.com/bevyengine/bevy/issues/7386
25 // Uncomment the lines below to show the current ambiguities in the RenderApp.
26 // let sub_app = app.sub_app_mut(bevy_render::RenderApp);
27 // configure_ambiguity_detection(sub_app);
28
29 app.finish();
30 app.cleanup();
31 app.update();
32
33 let main_app_ambiguities = count_ambiguities(app.main());
34 assert_eq!(
35 main_app_ambiguities.total(),
36 0,
37 "Main app has unexpected ambiguities among the following schedules: \n{main_app_ambiguities:#?}.",
38 );
39
40 // RenderApp is not checked here, because it is not within the App at this point.
41 let render_extract_ambiguities = count_ambiguities(app.sub_app(RenderExtractApp));
42 assert_eq!(
43 render_extract_ambiguities.total(),
44 0,
45 "RenderExtract app has unexpected ambiguities among the following schedules: \n{render_extract_ambiguities:#?}",
46 );
47}
Sourcepub fn main_mut(&mut self) -> &mut SubApp
pub fn main_mut(&mut self) -> &mut SubApp
Returns a mutable reference to the main SubApp
.
Examples found in repository?
14fn main() {
15 let mut app = App::new();
16 app.add_plugins(DefaultPlugins);
17
18 let main_app = app.main_mut();
19 configure_ambiguity_detection(main_app);
20 let render_extract_app = app.sub_app_mut(RenderExtractApp);
21 configure_ambiguity_detection(render_extract_app);
22
23 // Ambiguities in the RenderApp are currently allowed.
24 // Eventually, we should forbid these: see https://github.com/bevyengine/bevy/issues/7386
25 // Uncomment the lines below to show the current ambiguities in the RenderApp.
26 // let sub_app = app.sub_app_mut(bevy_render::RenderApp);
27 // configure_ambiguity_detection(sub_app);
28
29 app.finish();
30 app.cleanup();
31 app.update();
32
33 let main_app_ambiguities = count_ambiguities(app.main());
34 assert_eq!(
35 main_app_ambiguities.total(),
36 0,
37 "Main app has unexpected ambiguities among the following schedules: \n{main_app_ambiguities:#?}.",
38 );
39
40 // RenderApp is not checked here, because it is not within the App at this point.
41 let render_extract_ambiguities = count_ambiguities(app.sub_app(RenderExtractApp));
42 assert_eq!(
43 render_extract_ambiguities.total(),
44 0,
45 "RenderExtract app has unexpected ambiguities among the following schedules: \n{render_extract_ambiguities:#?}",
46 );
47}
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(&self, label: impl AppLabel) -> &SubApp
pub fn sub_app(&self, label: impl AppLabel) -> &SubApp
Examples found in repository?
14fn main() {
15 let mut app = App::new();
16 app.add_plugins(DefaultPlugins);
17
18 let main_app = app.main_mut();
19 configure_ambiguity_detection(main_app);
20 let render_extract_app = app.sub_app_mut(RenderExtractApp);
21 configure_ambiguity_detection(render_extract_app);
22
23 // Ambiguities in the RenderApp are currently allowed.
24 // Eventually, we should forbid these: see https://github.com/bevyengine/bevy/issues/7386
25 // Uncomment the lines below to show the current ambiguities in the RenderApp.
26 // let sub_app = app.sub_app_mut(bevy_render::RenderApp);
27 // configure_ambiguity_detection(sub_app);
28
29 app.finish();
30 app.cleanup();
31 app.update();
32
33 let main_app_ambiguities = count_ambiguities(app.main());
34 assert_eq!(
35 main_app_ambiguities.total(),
36 0,
37 "Main app has unexpected ambiguities among the following schedules: \n{main_app_ambiguities:#?}.",
38 );
39
40 // RenderApp is not checked here, because it is not within the App at this point.
41 let render_extract_ambiguities = count_ambiguities(app.sub_app(RenderExtractApp));
42 assert_eq!(
43 render_extract_ambiguities.total(),
44 0,
45 "RenderExtract app has unexpected ambiguities among the following schedules: \n{render_extract_ambiguities:#?}",
46 );
47}
Sourcepub fn sub_app_mut(&mut self, label: impl AppLabel) -> &mut SubApp
pub fn sub_app_mut(&mut self, label: impl AppLabel) -> &mut SubApp
Examples found in repository?
More examples
99 fn build(&self, app: &mut App) {
100 app.add_plugins(ExtractComponentPlugin::<InstanceMaterialData>::default());
101 app.sub_app_mut(RenderApp)
102 .add_render_command::<Transparent3d, DrawCustom>()
103 .init_resource::<SpecializedMeshPipelines<CustomPipeline>>()
104 .add_systems(
105 Render,
106 (
107 queue_custom.in_set(RenderSet::QueueMeshes),
108 prepare_instance_buffers.in_set(RenderSet::PrepareResources),
109 ),
110 );
111 }
112
113 fn finish(&self, app: &mut App) {
114 app.sub_app_mut(RenderApp).init_resource::<CustomPipeline>();
115 }
46 fn finish(&self, app: &mut App) {
47 let render_app = app.sub_app_mut(RenderApp);
48 render_app.init_resource::<ComputePipeline>().add_systems(
49 Render,
50 prepare_bind_group
51 .in_set(RenderSet::PrepareBindGroups)
52 // We don't need to recreate the bind group every frame
53 .run_if(not(resource_exists::<GpuBufferBindGroup>)),
54 );
55
56 // Add the compute node as a top level node to the render graph
57 // This means it will only execute once per frame
58 render_app
59 .world_mut()
60 .resource_mut::<RenderGraph>()
61 .add_node(ComputeNodeLabel, ComputeNode::default());
62 }
101 fn build(&self, app: &mut App) {
102 // Extract the game of life image resource from the main world into the render world
103 // for operation on by the compute shader and display on the sprite.
104 app.add_plugins(ExtractResourcePlugin::<GameOfLifeImages>::default());
105 let render_app = app.sub_app_mut(RenderApp);
106 render_app.add_systems(
107 Render,
108 prepare_bind_group.in_set(RenderSet::PrepareBindGroups),
109 );
110
111 let mut render_graph = render_app.world_mut().resource_mut::<RenderGraph>();
112 render_graph.add_node(GameOfLifeLabel, GameOfLifeNode::default());
113 render_graph.add_node_edge(GameOfLifeLabel, bevy::render::graph::CameraDriverLabel);
114 }
115
116 fn finish(&self, app: &mut App) {
117 let render_app = app.sub_app_mut(RenderApp);
118 render_app.init_resource::<GameOfLifePipeline>();
119 }
203 fn build(&self, app: &mut App) {
204 let (s, r) = crossbeam_channel::unbounded();
205
206 let render_app = app
207 .insert_resource(MainWorldReceiver(r))
208 .sub_app_mut(RenderApp);
209
210 let mut graph = render_app.world_mut().resource_mut::<RenderGraph>();
211 graph.add_node(ImageCopy, ImageCopyDriver);
212 graph.add_node_edge(bevy::render::graph::CameraDriverLabel, ImageCopy);
213
214 render_app
215 .insert_resource(RenderWorldSender(s))
216 // Make ImageCopiers accessible in RenderWorld system and plugin
217 .add_systems(ExtractSchedule, image_copy_extract)
218 // Receives image data from buffer to channel
219 // so we need to run it after the render graph is done
220 .add_systems(Render, receive_image_from_buffer.after(RenderSet::Render));
221 }
14fn main() {
15 let mut app = App::new();
16 app.add_plugins(DefaultPlugins);
17
18 let main_app = app.main_mut();
19 configure_ambiguity_detection(main_app);
20 let render_extract_app = app.sub_app_mut(RenderExtractApp);
21 configure_ambiguity_detection(render_extract_app);
22
23 // Ambiguities in the RenderApp are currently allowed.
24 // Eventually, we should forbid these: see https://github.com/bevyengine/bevy/issues/7386
25 // Uncomment the lines below to show the current ambiguities in the RenderApp.
26 // let sub_app = app.sub_app_mut(bevy_render::RenderApp);
27 // configure_ambiguity_detection(sub_app);
28
29 app.finish();
30 app.cleanup();
31 app.update();
32
33 let main_app_ambiguities = count_ambiguities(app.main());
34 assert_eq!(
35 main_app_ambiguities.total(),
36 0,
37 "Main app has unexpected ambiguities among the following schedules: \n{main_app_ambiguities:#?}.",
38 );
39
40 // RenderApp is not checked here, because it is not within the App at this point.
41 let render_extract_ambiguities = count_ambiguities(app.sub_app(RenderExtractApp));
42 assert_eq!(
43 render_extract_ambiguities.total(),
44 0,
45 "RenderExtract app has unexpected ambiguities among the following schedules: \n{render_extract_ambiguities:#?}",
46 );
47}
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.
Examples found in repository?
More examples
109 fn build(&self, app: &mut App) {
110 app.add_plugins(ExtractComponentPlugin::<CustomRenderedEntity>::default());
111
112 // We make sure to add these to the render app, not the main app.
113 let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
114 return;
115 };
116 render_app
117 // This is needed to tell bevy about your custom pipeline
118 .init_resource::<SpecializedMeshPipelines<CustomMeshPipeline>>()
119 // We need to use a custom draw command so we need to register it
120 .add_render_command::<Opaque3d, DrawSpecializedPipelineCommands>()
121 .add_systems(Render, queue_custom_mesh_pipeline.in_set(RenderSet::Queue));
122 }
123
124 fn finish(&self, app: &mut App) {
125 let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
126 return;
127 };
128 // Creating this pipeline needs the RenderDevice and RenderQueue
129 // which are only available once rendering plugins are initialized.
130 render_app.init_resource::<CustomMeshPipeline>();
131 }
169fn main() {
170 let mut app = App::new();
171 app.add_plugins(DefaultPlugins)
172 .add_plugins(ExtractComponentPlugin::<CustomRenderedEntity>::default())
173 .add_systems(Startup, setup);
174
175 // We make sure to add these to the render app, not the main app.
176 app.get_sub_app_mut(RenderApp)
177 .unwrap()
178 .init_resource::<CustomPhasePipeline>()
179 .init_resource::<SpecializedRenderPipelines<CustomPhasePipeline>>()
180 .add_render_command::<Opaque3d, DrawCustomPhaseItemCommands>()
181 .add_systems(
182 Render,
183 prepare_custom_phase_item_buffers.in_set(RenderSet::Prepare),
184 )
185 .add_systems(Render, queue_custom_phase_item.in_set(RenderSet::Queue));
186
187 app.run();
188}
45 fn finish(&self, app: &mut App) {
46 let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
47 return;
48 };
49
50 let render_device = render_app.world().resource::<RenderDevice>();
51
52 // Check if the device support the required feature. If not, exit the example.
53 // In a real application, you should setup a fallback for the missing feature
54 if !render_device
55 .features()
56 .contains(WgpuFeatures::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING)
57 {
58 error!(
59 "Render device doesn't support feature \
60SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING, \
61which is required for texture binding arrays"
62 );
63 exit(1);
64 }
65 }
297 fn build(&self, app: &mut App) {
298 // Load our custom shader
299 let mut shaders = app.world_mut().resource_mut::<Assets<Shader>>();
300 shaders.insert(
301 &COLORED_MESH2D_SHADER_HANDLE,
302 Shader::from_wgsl(COLORED_MESH2D_SHADER, file!()),
303 );
304 app.add_plugins(SyncComponentPlugin::<ColoredMesh2d>::default());
305
306 // Register our custom draw function, and add our render systems
307 app.get_sub_app_mut(RenderApp)
308 .unwrap()
309 .add_render_command::<Transparent2d, DrawColoredMesh2d>()
310 .init_resource::<SpecializedRenderPipelines<ColoredMesh2dPipeline>>()
311 .init_resource::<RenderColoredMesh2dInstances>()
312 .add_systems(
313 ExtractSchedule,
314 extract_colored_mesh2d.after(extract_mesh2d),
315 )
316 .add_systems(Render, queue_colored_mesh2d.in_set(RenderSet::QueueMeshes));
317 }
318
319 fn finish(&self, app: &mut App) {
320 // Register our custom pipeline
321 app.get_sub_app_mut(RenderApp)
322 .unwrap()
323 .init_resource::<ColoredMesh2dPipeline>();
324 }
115 fn build(&self, app: &mut App) {
116 app.add_plugins((
117 ExtractComponentPlugin::<DrawStencil>::default(),
118 SortedRenderPhasePlugin::<Stencil3d, MeshPipeline>::new(RenderDebugFlags::default()),
119 ));
120 // We need to get the render app from the main app
121 let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
122 return;
123 };
124 render_app
125 .init_resource::<SpecializedMeshPipelines<StencilPipeline>>()
126 .init_resource::<DrawFunctions<Stencil3d>>()
127 .add_render_command::<Stencil3d, DrawMesh3dStencil>()
128 .init_resource::<ViewSortedRenderPhases<Stencil3d>>()
129 .add_systems(ExtractSchedule, extract_camera_phases)
130 .add_systems(
131 Render,
132 (
133 queue_custom_meshes.in_set(RenderSet::QueueMeshes),
134 sort_phase_system::<Stencil3d>.in_set(RenderSet::PhaseSort),
135 batch_and_prepare_sorted_render_phase::<Stencil3d, StencilPipeline>
136 .in_set(RenderSet::PrepareResources),
137 ),
138 );
139
140 render_app
141 .add_render_graph_node::<ViewNodeRunner<CustomDrawNode>>(Core3d, CustomDrawPassLabel)
142 // Tell the node to run after the main pass
143 .add_render_graph_edges(Core3d, (Node3d::MainOpaquePass, CustomDrawPassLabel));
144 }
145
146 fn finish(&self, app: &mut App) {
147 // We need to get the render app from the main app
148 let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
149 return;
150 };
151 // The pipeline needs the RenderDevice to be created and it's only available once plugins
152 // are initialized
153 render_app.init_resource::<StencilPipeline>();
154 }
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.
Examples found in repository?
16fn main() {
17 let mut app = App::new();
18
19 // Create a new [`Schedule`]. For demonstration purposes, we configure it to use a single threaded executor so that
20 // systems in this schedule are never run in parallel. However, this is not a requirement for custom schedules in
21 // general.
22 let mut custom_update_schedule = Schedule::new(SingleThreadedUpdate);
23 custom_update_schedule.set_executor_kind(ExecutorKind::SingleThreaded);
24
25 // Adding the schedule to the app does not automatically run the schedule. This merely registers the schedule so
26 // that systems can look it up using the `Schedules` resource.
27 app.add_schedule(custom_update_schedule);
28
29 // Bevy `App`s have a `main_schedule_label` field that configures which schedule is run by the App's `runner`.
30 // By default, this is `Main`. The `Main` schedule is responsible for running Bevy's main schedules such as
31 // `Update`, `Startup` or `Last`.
32 //
33 // We can configure the `Main` schedule to run our custom update schedule relative to the existing ones by modifying
34 // the `MainScheduleOrder` resource.
35 //
36 // Note that we modify `MainScheduleOrder` directly in `main` and not in a startup system. The reason for this is
37 // that the `MainScheduleOrder` cannot be modified from systems that are run as part of the `Main` schedule.
38 let mut main_schedule_order = app.world_mut().resource_mut::<MainScheduleOrder>();
39 main_schedule_order.insert_after(Update, SingleThreadedUpdate);
40
41 // Adding a custom startup schedule works similarly, but needs to use `insert_startup_after`
42 // instead of `insert_after`.
43 app.add_schedule(Schedule::new(CustomStartup));
44
45 let mut main_schedule_order = app.world_mut().resource_mut::<MainScheduleOrder>();
46 main_schedule_order.insert_startup_after(PreStartup, CustomStartup);
47
48 app.add_systems(SingleThreadedUpdate, single_threaded_update_system)
49 .add_systems(CustomStartup, custom_startup_system)
50 .add_systems(PreStartup, pre_startup_system)
51 .add_systems(Startup, startup_system)
52 .add_systems(First, first_system)
53 .add_systems(Update, update_system)
54 .add_systems(Last, last_system)
55 .run();
56}
More examples
79fn stress_test(num_entities: u32, num_components: u32, num_systems: u32) {
80 let mut rng = ChaCha8Rng::seed_from_u64(42);
81 let mut app = App::default();
82 let world = app.world_mut();
83
84 // register a bunch of components
85 let component_ids: Vec<ComponentId> = (1..=num_components)
86 .map(|i| {
87 world.register_component_with_descriptor(
88 // SAFETY:
89 // * We don't implement a drop function
90 // * u8 is Sync and Send
91 unsafe {
92 ComponentDescriptor::new_with_layout(
93 format!("Component{}", i).to_string(),
94 StorageType::Table,
95 Layout::new::<u8>(),
96 None,
97 true, // is mutable
98 ComponentCloneBehavior::Default,
99 )
100 },
101 )
102 })
103 .collect();
104
105 // fill the schedule with systems
106 let mut schedule = Schedule::new(Update);
107 for _ in 1..=num_systems {
108 let num_access_components = rng.gen_range(1..10);
109 let access_components: Vec<ComponentId> = component_ids
110 .choose_multiple(&mut rng, num_access_components)
111 .copied()
112 .collect();
113 let system = (QueryParamBuilder::new(|builder| {
114 for &access_component in &access_components {
115 if rand::random::<bool>() {
116 builder.mut_id(access_component);
117 } else {
118 builder.ref_id(access_component);
119 }
120 }
121 }),)
122 .build_state(world)
123 .build_any_system(base_system);
124 schedule.add_systems((move || access_components.clone()).pipe(system));
125 }
126
127 // spawn a bunch of entities
128 for _ in 1..=num_entities {
129 let num_components = rng.gen_range(1..10);
130 let components: Vec<ComponentId> = component_ids
131 .choose_multiple(&mut rng, num_components)
132 .copied()
133 .collect();
134
135 let mut entity = world.spawn_empty();
136 // We use `ManuallyDrop` here as we need to avoid dropping the u8's when `values` is dropped
137 // since ownership of the values is passed to the world in `insert_by_ids`.
138 // But we do want to deallocate the memory when values is dropped.
139 let mut values: Vec<ManuallyDrop<u8>> = components
140 .iter()
141 .map(|_id| ManuallyDrop::new(rng.gen_range(0..255)))
142 .collect();
143 let ptrs: Vec<OwningPtr> = values
144 .iter_mut()
145 .map(|value| {
146 // SAFETY:
147 // * We don't read/write `values` binding after this and values are `ManuallyDrop`,
148 // so we have the right to drop/move the values
149 unsafe { PtrMut::from(value).promote() }
150 })
151 .collect();
152 // SAFETY:
153 // * component_id's are from the same world
154 // * `values` was initialized above, so references are valid
155 unsafe {
156 entity.insert_by_ids(&components, ptrs.into_iter());
157 }
158 }
159
160 println!(
161 "Number of Archetype-Components: {}",
162 world.archetypes().archetype_components_len()
163 );
164
165 // overwrite Update schedule in the app
166 app.add_schedule(schedule);
167 app.add_plugins(MinimalPlugins)
168 .add_plugins(DiagnosticsPlugin)
169 .add_plugins(LogPlugin::default())
170 .add_plugins(FrameTimeDiagnosticsPlugin::default())
171 .add_plugins(LogDiagnosticsPlugin::filtered(vec![DiagnosticPath::new(
172 "fps",
173 )]));
174 app.run();
175}
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.
Examples found in repository?
34 fn build(&self, app: &mut App) {
35 app.add_systems(Startup, build_stepping_hint);
36 if cfg!(not(feature = "bevy_debug_stepping")) {
37 return;
38 }
39
40 // create and insert our debug schedule into the main schedule order.
41 // We need an independent schedule so we have access to all other
42 // schedules through the `Stepping` resource
43 app.init_schedule(DebugSchedule);
44 let mut order = app.world_mut().resource_mut::<MainScheduleOrder>();
45 order.insert_after(Update, DebugSchedule);
46
47 // create our stepping resource
48 let mut stepping = Stepping::new();
49 for label in &self.schedule_labels {
50 stepping.add_schedule(*label);
51 }
52 app.insert_resource(stepping);
53
54 // add our startup & stepping systems
55 app.insert_resource(State {
56 ui_top: self.top,
57 ui_left: self.left,
58 systems: Vec::new(),
59 })
60 .add_systems(
61 DebugSchedule,
62 (
63 build_ui.run_if(not(initialized)),
64 handle_input,
65 update_ui.run_if(initialized),
66 )
67 .chain(),
68 );
69 }
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.
Examples found in repository?
20fn main() {
21 App::new()
22 // We can modify the reporting strategy for system execution order ambiguities on a per-schedule basis.
23 // You must do this for each schedule you want to inspect; child schedules executed within an inspected
24 // schedule do not inherit this modification.
25 .edit_schedule(Update, |schedule| {
26 schedule.set_build_settings(ScheduleBuildSettings {
27 ambiguity_detection: LogLevel::Warn,
28 ..default()
29 });
30 })
31 .init_resource::<A>()
32 .init_resource::<B>()
33 .add_systems(
34 Update,
35 (
36 // This pair of systems has an ambiguous order,
37 // as their data access conflicts, and there's no order between them.
38 reads_a,
39 writes_a,
40 // This pair of systems has conflicting data access,
41 // but it's resolved with an explicit ordering:
42 // the .after relationship here means that we will always double after adding.
43 adds_one_to_b,
44 doubles_b.after(adds_one_to_b),
45 // This system isn't ambiguous with adds_one_to_b,
46 // due to the transitive ordering created by our constraints:
47 // if A is before B is before C, then A must be before C as well.
48 reads_b.after(doubles_b),
49 // This system will conflict with all of our writing systems
50 // but we've silenced its ambiguity with adds_one_to_b.
51 // This should only be done in the case of clear false positives:
52 // leave a comment in your code justifying the decision!
53 reads_a_and_b.ambiguous_with(adds_one_to_b),
54 ),
55 )
56 // Be mindful, internal ambiguities are reported too!
57 // If there are any ambiguities due solely to DefaultPlugins,
58 // or between DefaultPlugins and any of your third party plugins,
59 // please file a bug with the repo responsible!
60 // Only *you* can prevent nondeterministic bugs due to greedy parallelism.
61 .add_plugins(DefaultPlugins)
62 .run();
63}
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.
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>
Attempts to determine if an AppExit
was raised since the last update.
Will attempt to return the first Error
it encounters.
This should be called after every update()
otherwise you risk
dropping possible AppExit
events.
Examples found in repository?
10fn my_runner(mut app: App) -> AppExit {
11 // Finalize plugin building, including running any necessary clean-up.
12 // This is normally completed by the default runner.
13 app.finish();
14 app.cleanup();
15
16 println!("Type stuff into the console");
17 for line in io::stdin().lines() {
18 {
19 let mut input = app.world_mut().resource_mut::<Input>();
20 input.0 = line.unwrap();
21 }
22 app.update();
23
24 if let Some(exit) = app.should_exit() {
25 return exit;
26 }
27 }
28
29 AppExit::Success
30}
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.
§Examples
// An observer system can be any system where the first parameter is a trigger
app.add_observer(|trigger: Trigger<Party>, friends: Query<Entity, With<Friend>>, mut commands: Commands| {
if trigger.event().friends_allowed {
for friend in friends.iter() {
commands.trigger_targets(Invite, friend);
}
}
});
Examples found in repository?
More examples
8fn main() {
9 App::new()
10 .add_plugins((MinimalPlugins, LogPlugin::default()))
11 .add_systems(Startup, setup)
12 .add_systems(
13 Update,
14 attack_armor.run_if(on_timer(Duration::from_millis(200))),
15 )
16 // Add a global observer that will emit a line whenever an attack hits an entity.
17 .add_observer(attack_hits)
18 .run();
19}
14fn main() {
15 App::new()
16 .insert_resource(AmbientLight {
17 color: Color::WHITE,
18 brightness: 2000.,
19 ..default()
20 })
21 .add_plugins(DefaultPlugins)
22 .init_resource::<ParticleAssets>()
23 .init_resource::<FoxFeetTargets>()
24 .add_systems(Startup, setup)
25 .add_systems(Update, setup_scene_once_loaded)
26 .add_systems(Update, simulate_particles)
27 .add_observer(observe_on_step)
28 .run();
29}
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 enable_state_scoped_entities<S>(&mut self) -> &mut Appwhere
S: States,
fn enable_state_scoped_entities<S>(&mut self) -> &mut Appwhere
S: States,
S
. Read moreSource§fn register_type_state<S>(&mut self) -> &mut App
fn register_type_state<S>(&mut self) -> &mut App
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
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 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 RenderGraphApp for App
impl RenderGraphApp 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 StateScopedEventsAppExt for App
impl StateScopedEventsAppExt for App
Source§fn add_state_scoped_event<E>(
&mut self,
state: impl FreelyMutableState,
) -> &mut Appwhere
E: Event,
fn add_state_scoped_event<E>(
&mut self,
state: impl FreelyMutableState,
) -> &mut Appwhere
E: Event,
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> 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<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<T> Pointable for T
impl<T> Pointable for T
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<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.