You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Creates a new entity with the components contained in `bundle`.
194
+
///
195
+
/// Note that `bundle` is a [DynamicBundle], which is a collection of components. [DynamicBundle] is automatically implemented for tuples of components. You can also create your own bundle types by deriving [`derive@Bundle`]. If you would like to spawn an entity with a single component, consider wrapping the component in a tuple (which [DynamicBundle] is implemented for).
196
+
///
197
+
/// See [`Self::set_current_entity`], [`Self::insert`].
198
+
///
199
+
/// # Example
200
+
///
201
+
/// ```
202
+
/// use bevy_ecs::prelude::*;
203
+
///
204
+
/// struct Component1;
205
+
/// struct Component2;
206
+
///
207
+
/// #[derive(Bundle)]
208
+
/// struct ExampleBundle {
209
+
/// a: Component1,
210
+
/// b: Component2,
211
+
/// }
212
+
///
213
+
/// fn example_system(mut commands: Commands) {
214
+
/// // Create a new entity with a component bundle.
215
+
/// commands.spawn(ExampleBundle {
216
+
/// a: Component1,
217
+
/// b: Component2,
218
+
/// });
219
+
///
220
+
/// // Create a new entity with a single component.
let current_entity = self.current_entity.expect("Cannot add bundle because the 'current entity' is not set. You should spawn an entity first.");
268
314
self.commands.push(Box::new(Insert{
269
315
entity: current_entity,
270
-
components,
316
+
bundle,
271
317
}));
272
318
self
273
319
}
274
320
321
+
/// Adds a single component to the current entity.
322
+
///
323
+
/// See [`Self::with_bundle`], [`Self::current_entity`].
324
+
///
325
+
/// # Warning
326
+
///
327
+
/// It's possible to call this with a bundle, but this is likely not intended and [`Self::with_bundle`] should be used instead. If `with` is called with a bundle, the bundle itself will be added as a component instead of the bundles' inner components each being added.
328
+
///
329
+
/// # Example
330
+
///
331
+
/// `with` can be chained with [`Self::spawn`].
332
+
///
333
+
/// ```
334
+
/// use bevy_ecs::prelude::*;
335
+
///
336
+
/// struct Component1;
337
+
/// struct Component2;
338
+
///
339
+
/// fn example_system(mut commands: Commands) {
340
+
/// // Create a new entity with a `Component1` and `Component2`.
0 commit comments