Skip to main content

bevy_internal/
default_plugins.rs

1use bevy_app::{plugin_group, Plugin};
2
3plugin_group! {
4    /// This plugin group will add all the default plugins for a *Bevy* application:
5    pub struct DefaultPlugins {
6        bevy_app:::PanicHandlerPlugin,
7        #[cfg(feature = "bevy_log")]
8        bevy_log:::LogPlugin,
9        bevy_app:::TaskPoolPlugin,
10        bevy_diagnostic:::FrameCountPlugin,
11        bevy_time:::TimePlugin,
12        bevy_transform:::TransformPlugin,
13        bevy_diagnostic:::DiagnosticsPlugin,
14        bevy_input:::InputPlugin,
15        #[cfg(feature = "bevy_input_focus")]
16        bevy_input_focus:::InputFocusPlugin,
17        #[cfg(feature = "bevy_input_focus")]
18        bevy_input_focus:::InputDispatchPlugin,
19        #[custom(cfg(not(feature = "bevy_window")))]
20        bevy_app:::ScheduleRunnerPlugin,
21        #[cfg(feature = "bevy_window")]
22        bevy_window:::WindowPlugin,
23        #[cfg(feature = "bevy_window")]
24        bevy_a11y:::AccessibilityPlugin,
25        #[cfg(feature = "std")]
26        #[custom(cfg(any(all(unix, not(target_os = "horizon")), windows)))]
27        bevy_app:::TerminalCtrlCHandlerPlugin,
28        // NOTE: Load this before AssetPlugin to properly register http asset sources.
29        #[cfg(feature = "bevy_asset")]
30        #[custom(cfg(any(feature = "http", feature = "https")))]
31        bevy_asset::io::web:::WebAssetPlugin,
32        #[cfg(feature = "bevy_asset")]
33        bevy_asset:::AssetPlugin,
34        #[cfg(feature = "bevy_world_serialization")]
35        bevy_world_serialization:::WorldSerializationPlugin,
36        #[cfg(feature = "bevy_scene")]
37        bevy_scene:::ScenePlugin,
38        // NOTE: WinitPlugin needs to be after AssetPlugin because of custom cursors.
39        #[cfg(feature = "bevy_winit")]
40        bevy_winit:::WinitPlugin,
41        #[custom(cfg(all(feature = "dlss", not(feature = "force_disable_dlss"))))]
42        bevy_anti_alias::dlss:::DlssInitPlugin,
43        #[cfg(feature = "bevy_render")]
44        bevy_render:::RenderPlugin,
45        // NOTE: Load this after renderer initialization so that it knows about the supported
46        // compressed texture formats.
47        #[cfg(feature = "bevy_image")]
48        bevy_image:::ImagePlugin,
49        #[cfg(feature = "bevy_mesh")]
50        bevy_mesh:::MeshPlugin,
51        #[cfg(feature = "bevy_camera")]
52        bevy_camera:::CameraPlugin,
53        #[cfg(feature = "bevy_light")]
54        bevy_light:::LightPlugin,
55        #[cfg(feature = "bevy_render")]
56        #[custom(cfg(all(not(target_arch = "wasm32"), feature = "multi_threaded")))]
57        bevy_render::pipelined_rendering:::PipelinedRenderingPlugin,
58        #[cfg(feature = "bevy_core_pipeline")]
59        bevy_core_pipeline:::CorePipelinePlugin,
60        #[cfg(feature = "bevy_post_process")]
61        bevy_post_process:::PostProcessPlugin,
62        #[cfg(feature = "bevy_anti_alias")]
63        bevy_anti_alias:::AntiAliasPlugin,
64        #[cfg(feature = "bevy_sprite")]
65        bevy_sprite:::SpritePlugin,
66        #[cfg(feature = "bevy_sprite_render")]
67        bevy_sprite_render:::SpriteRenderPlugin,
68        #[cfg(feature = "bevy_clipboard")]
69        bevy_clipboard:::ClipboardPlugin,
70        #[cfg(feature = "bevy_text")]
71        bevy_text:::TextPlugin,
72        #[cfg(feature = "bevy_ui")]
73        bevy_ui:::UiPlugin,
74        #[cfg(feature = "bevy_ui_render")]
75        bevy_ui_render:::UiRenderPlugin,
76        #[cfg(feature = "bevy_gltf")]
77        bevy_gltf:::GltfPlugin,
78        #[cfg(feature = "bevy_pbr")]
79        bevy_pbr:::PbrPlugin,
80        #[cfg(feature = "bevy_audio")]
81        bevy_audio:::AudioPlugin,
82        #[cfg(feature = "bevy_gilrs")]
83        bevy_gilrs:::GilrsPlugin,
84        #[cfg(feature = "bevy_animation")]
85        bevy_animation:::AnimationPlugin,
86        #[cfg(feature = "bevy_gizmos")]
87        bevy_gizmos:::GizmoPlugin,
88        #[cfg(feature = "bevy_gizmos_render")]
89        bevy_gizmos_render:::GizmoRenderPlugin,
90        #[cfg(feature = "bevy_state")]
91        bevy_state::app:::StatesPlugin,
92        #[cfg(feature = "bevy_ci_testing")]
93        bevy_dev_tools::ci_testing:::CiTestingPlugin,
94        #[custom(cfg(all(feature = "bevy_dev_tools", feature = "bevy_pbr")))]
95        bevy_dev_tools::render_debug:::RenderDebugOverlayPlugin,
96        #[cfg(feature = "hotpatching")]
97        bevy_app::hotpatch:::HotPatchPlugin,
98        #[plugin_group]
99        #[cfg(feature = "bevy_ui_widgets")]
100        bevy_ui_widgets:::UiWidgetsPlugins,
101        #[plugin_group]
102        #[cfg(feature = "bevy_picking")]
103        bevy_picking:::DefaultPickingPlugins,
104        #[doc(hidden)]
105        :IgnoreAmbiguitiesPlugin,
106    }
107    /// [`DefaultPlugins`] obeys *Cargo* *feature* flags. Users may exert control over this plugin group
108    /// by disabling `default-features` in their `Cargo.toml` and enabling only those features
109    /// that they wish to use.
110    ///
111    /// [`DefaultPlugins`] contains all the plugins typically required to build
112    /// a *Bevy* application which includes a *window* and presentation components.
113    /// For the absolute minimum number of plugins needed to run a Bevy application, see [`MinimalPlugins`].
114}
115
116#[derive(Default)]
117struct IgnoreAmbiguitiesPlugin;
118
119impl Plugin for IgnoreAmbiguitiesPlugin {
120    #[expect(
121        clippy::allow_attributes,
122        reason = "`unused_variables` is not always linted"
123    )]
124    #[allow(
125        unused_variables,
126        reason = "The `app` parameter is used only if a combination of crates that contain ambiguities with each other are enabled."
127    )]
128    fn build(&self, app: &mut bevy_app::App) {
129        #[cfg(all(feature = "bevy_ui_widgets", feature = "bevy_sprite"))]
130        if app.is_plugin_added::<bevy_ui_widgets::EditableTextInputPlugin>()
131            && app.is_plugin_added::<bevy_sprite::SpritePlugin>()
132        {
133            // update_ime_position reads Window to reposition the IME cursor, while
134            // update_text2d_layout writes Window bounds for text wrapping.
135            app.ignore_ambiguity(
136                bevy_app::PostUpdate,
137                bevy_ui_widgets::ImeSystems::UpdatePosition,
138                bevy_sprite::update_text2d_layout,
139            );
140        }
141
142        // bevy_ui owns the Transform and cannot be animated
143        #[cfg(all(feature = "bevy_animation", feature = "bevy_ui"))]
144        if app.is_plugin_added::<bevy_animation::AnimationPlugin>()
145            && app.is_plugin_added::<bevy_ui::UiPlugin>()
146        {
147            app.ignore_ambiguity(
148                bevy_app::PostUpdate,
149                bevy_animation::advance_animations,
150                bevy_ui::ui_layout_system,
151            );
152            app.ignore_ambiguity(
153                bevy_app::PostUpdate,
154                bevy_animation::animate_targets,
155                bevy_ui::ui_layout_system,
156            );
157        }
158    }
159}
160
161plugin_group! {
162    /// This plugin group will add the minimal plugins for a *Bevy* application:
163    pub struct MinimalPlugins {
164        bevy_app:::TaskPoolPlugin,
165        bevy_diagnostic:::FrameCountPlugin,
166        bevy_time:::TimePlugin,
167        bevy_app:::ScheduleRunnerPlugin,
168        #[cfg(feature = "bevy_ci_testing")]
169        bevy_dev_tools::ci_testing:::CiTestingPlugin,
170    }
171    /// This plugin group represents the absolute minimum, bare-bones, bevy application.
172    /// Use this if you want to have absolute control over the plugins used.
173    ///
174    /// It includes a [schedule runner (`ScheduleRunnerPlugin`)](crate::app::ScheduleRunnerPlugin)
175    /// to provide functionality that would otherwise be driven by a windowed application's
176    /// *event loop* or *message loop*.
177    ///
178    /// By default, this loop will run as fast as possible, which can result in high CPU usage.
179    /// You can add a delay using [`run_loop`](crate::app::ScheduleRunnerPlugin::run_loop),
180    /// or remove the loop using [`run_once`](crate::app::ScheduleRunnerPlugin::run_once).
181    /// # Example:
182    /// ```rust, no_run
183    /// # use std::time::Duration;
184    /// # use bevy_app::{App, PluginGroup, ScheduleRunnerPlugin};
185    /// # use bevy_internal::MinimalPlugins;
186    /// App::new().add_plugins(MinimalPlugins.set(ScheduleRunnerPlugin::run_loop(
187    ///     // Run 60 times per second.
188    ///     Duration::from_secs_f64(1.0 / 60.0),
189    /// ))).run();
190}