2022-05-16 13:53:20 +00:00
|
|
|
//! This example shows how to use the ECS and the [`AsyncComputeTaskPool`]
|
|
|
|
//! to spawn, poll, and complete tasks across systems and system ticks.
|
|
|
|
|
2021-05-23 20:13:55 +00:00
|
|
|
use bevy::{
|
2023-11-22 00:04:37 +00:00
|
|
|
ecs::system::{CommandQueue, SystemState},
|
2021-05-23 20:13:55 +00:00
|
|
|
prelude::*,
|
2023-11-21 16:51:13 +00:00
|
|
|
tasks::{block_on, futures_lite::future, AsyncComputeTaskPool, Task},
|
2021-05-23 20:13:55 +00:00
|
|
|
};
|
|
|
|
use rand::Rng;
|
2024-02-14 02:29:26 +00:00
|
|
|
use std::{thread, time::Duration};
|
2021-05-23 20:13:55 +00:00
|
|
|
|
|
|
|
fn main() {
|
2021-07-27 20:21:06 +00:00
|
|
|
App::new()
|
2021-05-23 20:13:55 +00:00
|
|
|
.add_plugins(DefaultPlugins)
|
2023-03-18 01:45:34 +00:00
|
|
|
.add_systems(Startup, (setup_env, add_assets, spawn_tasks))
|
|
|
|
.add_systems(Update, handle_tasks)
|
2021-05-23 20:13:55 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Number of cubes to spawn across the x, y, and z axis
|
|
|
|
const NUM_CUBES: u32 = 6;
|
|
|
|
|
Make `Resource` trait opt-in, requiring `#[derive(Resource)]` V2 (#5577)
*This PR description is an edited copy of #5007, written by @alice-i-cecile.*
# Objective
Follow-up to https://github.com/bevyengine/bevy/pull/2254. The `Resource` trait currently has a blanket implementation for all types that meet its bounds.
While ergonomic, this results in several drawbacks:
* it is possible to make confusing, silent mistakes such as inserting a function pointer (Foo) rather than a value (Foo::Bar) as a resource
* it is challenging to discover if a type is intended to be used as a resource
* we cannot later add customization options (see the [RFC](https://github.com/bevyengine/rfcs/blob/main/rfcs/27-derive-component.md) for the equivalent choice for Component).
* dependencies can use the same Rust type as a resource in invisibly conflicting ways
* raw Rust types used as resources cannot preserve privacy appropriately, as anyone able to access that type can read and write to internal values
* we cannot capture a definitive list of possible resources to display to users in an editor
## Notes to reviewers
* Review this commit-by-commit; there's effectively no back-tracking and there's a lot of churn in some of these commits.
*ira: My commits are not as well organized :')*
* I've relaxed the bound on Local to Send + Sync + 'static: I don't think these concerns apply there, so this can keep things simple. Storing e.g. a u32 in a Local is fine, because there's a variable name attached explaining what it does.
* I think this is a bad place for the Resource trait to live, but I've left it in place to make reviewing easier. IMO that's best tackled with https://github.com/bevyengine/bevy/issues/4981.
## Changelog
`Resource` is no longer automatically implemented for all matching types. Instead, use the new `#[derive(Resource)]` macro.
## Migration Guide
Add `#[derive(Resource)]` to all types you are using as a resource.
If you are using a third party type as a resource, wrap it in a tuple struct to bypass orphan rules. Consider deriving `Deref` and `DerefMut` to improve ergonomics.
`ClearColor` no longer implements `Component`. Using `ClearColor` as a component in 0.8 did nothing.
Use the `ClearColorConfig` in the `Camera3d` and `Camera2d` components instead.
Co-authored-by: Alice <alice.i.cecile@gmail.com>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: devil-ira <justthecooldude@gmail.com>
Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2022-08-08 21:36:35 +00:00
|
|
|
#[derive(Resource, Deref)]
|
2021-05-23 20:13:55 +00:00
|
|
|
struct BoxMeshHandle(Handle<Mesh>);
|
Make `Resource` trait opt-in, requiring `#[derive(Resource)]` V2 (#5577)
*This PR description is an edited copy of #5007, written by @alice-i-cecile.*
# Objective
Follow-up to https://github.com/bevyengine/bevy/pull/2254. The `Resource` trait currently has a blanket implementation for all types that meet its bounds.
While ergonomic, this results in several drawbacks:
* it is possible to make confusing, silent mistakes such as inserting a function pointer (Foo) rather than a value (Foo::Bar) as a resource
* it is challenging to discover if a type is intended to be used as a resource
* we cannot later add customization options (see the [RFC](https://github.com/bevyengine/rfcs/blob/main/rfcs/27-derive-component.md) for the equivalent choice for Component).
* dependencies can use the same Rust type as a resource in invisibly conflicting ways
* raw Rust types used as resources cannot preserve privacy appropriately, as anyone able to access that type can read and write to internal values
* we cannot capture a definitive list of possible resources to display to users in an editor
## Notes to reviewers
* Review this commit-by-commit; there's effectively no back-tracking and there's a lot of churn in some of these commits.
*ira: My commits are not as well organized :')*
* I've relaxed the bound on Local to Send + Sync + 'static: I don't think these concerns apply there, so this can keep things simple. Storing e.g. a u32 in a Local is fine, because there's a variable name attached explaining what it does.
* I think this is a bad place for the Resource trait to live, but I've left it in place to make reviewing easier. IMO that's best tackled with https://github.com/bevyengine/bevy/issues/4981.
## Changelog
`Resource` is no longer automatically implemented for all matching types. Instead, use the new `#[derive(Resource)]` macro.
## Migration Guide
Add `#[derive(Resource)]` to all types you are using as a resource.
If you are using a third party type as a resource, wrap it in a tuple struct to bypass orphan rules. Consider deriving `Deref` and `DerefMut` to improve ergonomics.
`ClearColor` no longer implements `Component`. Using `ClearColor` as a component in 0.8 did nothing.
Use the `ClearColorConfig` in the `Camera3d` and `Camera2d` components instead.
Co-authored-by: Alice <alice.i.cecile@gmail.com>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: devil-ira <justthecooldude@gmail.com>
Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2022-08-08 21:36:35 +00:00
|
|
|
|
|
|
|
#[derive(Resource, Deref)]
|
2021-05-23 20:13:55 +00:00
|
|
|
struct BoxMaterialHandle(Handle<StandardMaterial>);
|
|
|
|
|
|
|
|
/// Startup system which runs only once and generates our Box Mesh
|
|
|
|
/// and Box Material assets, adds them to their respective Asset
|
|
|
|
/// Resources, and stores their handles as resources so we can access
|
|
|
|
/// them later when we're ready to render our Boxes
|
|
|
|
fn add_assets(
|
|
|
|
mut commands: Commands,
|
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
|
|
) {
|
2024-02-08 18:01:34 +00:00
|
|
|
let box_mesh_handle = meshes.add(Cuboid::new(0.25, 0.25, 0.25));
|
2021-05-23 20:13:55 +00:00
|
|
|
commands.insert_resource(BoxMeshHandle(box_mesh_handle));
|
|
|
|
|
Use `impl Into<A>` for `Assets::add` (#10878)
# Motivation
When spawning entities into a scene, it is very common to create assets
like meshes and materials and to add them via asset handles. A common
setup might look like this:
```rust
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(StandardMaterial::from(Color::RED)),
..default()
});
}
```
Let's take a closer look at the part that adds the assets using `add`.
```rust
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(StandardMaterial::from(Color::RED)),
```
Here, "mesh" and "material" are both repeated three times. It's very
explicit, but I find it to be a bit verbose. In addition to being more
code to read and write, the extra characters can sometimes also lead to
the code being formatted to span multiple lines even though the core
task, adding e.g. a primitive mesh, is extremely simple.
A way to address this is by using `.into()`:
```rust
mesh: meshes.add(shape::Cube { size: 1.0 }.into()),
material: materials.add(Color::RED.into()),
```
This is fine, but from the names and the type of `meshes`, we already
know what the type should be. It's very clear that `Cube` should be
turned into a `Mesh` because of the context it's used in. `.into()` is
just seven characters, but it's so common that it quickly adds up and
gets annoying.
It would be nice if you could skip all of the conversion and let Bevy
handle it for you:
```rust
mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::RED),
```
# Objective
Make adding assets more ergonomic by making `Assets::add` take an `impl
Into<A>` instead of `A`.
## Solution
`Assets::add` now takes an `impl Into<A>` instead of `A`, so e.g. this
works:
```rust
commands.spawn(PbrBundle {
mesh: meshes.add(shape::Cube { size: 1.0 }),
material: materials.add(Color::RED),
..default()
});
```
I also changed all examples to use this API, which increases consistency
as well because `Mesh::from` and `into` were being used arbitrarily even
in the same file. This also gets rid of some lines of code because
formatting is nicer.
---
## Changelog
- `Assets::add` now takes an `impl Into<A>` instead of `A`
- Examples don't use `T::from(K)` or `K.into()` when adding assets
## Migration Guide
Some `into` calls that worked previously might now be broken because of
the new trait bounds. You need to either remove `into` or perform the
conversion explicitly with `from`:
```rust
// Doesn't compile
let mesh_handle = meshes.add(shape::Cube { size: 1.0 }.into()),
// These compile
let mesh_handle = meshes.add(shape::Cube { size: 1.0 }),
let mesh_handle = meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
```
## Concerns
I believe the primary concerns might be:
1. Is this too implicit?
2. Does this increase codegen bloat?
Previously, the two APIs were using `into` or `from`, and now it's
"nothing" or `from`. You could argue that `into` is slightly more
explicit than "nothing" in cases like the earlier examples where a
`Color` gets converted to e.g. a `StandardMaterial`, but I personally
don't think `into` adds much value even in this case, and you could
still see the actual type from the asset type.
As for codegen bloat, I doubt it adds that much, but I'm not very
familiar with the details of codegen. I personally value the user-facing
code reduction and ergonomics improvements that these changes would
provide, but it might be worth checking the other effects in more
detail.
Another slight concern is migration pain; apps might have a ton of
`into` calls that would need to be removed, and it did take me a while
to do so for Bevy itself (maybe around 20-40 minutes). However, I think
the fact that there *are* so many `into` calls just highlights that the
API could be made nicer, and I'd gladly migrate my own projects for it.
2024-01-08 22:14:43 +00:00
|
|
|
let box_material_handle = materials.add(Color::rgb(1.0, 0.2, 0.3));
|
2021-05-23 20:13:55 +00:00
|
|
|
commands.insert_resource(BoxMaterialHandle(box_material_handle));
|
|
|
|
}
|
|
|
|
|
2022-04-22 06:29:38 +00:00
|
|
|
#[derive(Component)]
|
2023-11-22 00:04:37 +00:00
|
|
|
struct ComputeTransform(Task<CommandQueue>);
|
2022-04-22 06:29:38 +00:00
|
|
|
|
2021-05-23 20:13:55 +00:00
|
|
|
/// This system generates tasks simulating computationally intensive
|
|
|
|
/// work that potentially spans multiple frames/ticks. A separate
|
2023-04-23 17:28:36 +00:00
|
|
|
/// system, [`handle_tasks`], will poll the spawned tasks on subsequent
|
2021-05-23 20:13:55 +00:00
|
|
|
/// frames/ticks, and use the results to spawn cubes
|
Add global init and get accessors for all newtyped TaskPools (#2250)
Right now, a direct reference to the target TaskPool is required to launch tasks on the pools, despite the three newtyped pools (AsyncComputeTaskPool, ComputeTaskPool, and IoTaskPool) effectively acting as global instances. The need to pass a TaskPool reference adds notable friction to spawning subtasks within existing tasks. Possible use cases for this may include chaining tasks within the same pool like spawning separate send/receive I/O tasks after waiting on a network connection to be established, or allowing cross-pool dependent tasks like starting dependent multi-frame computations following a long I/O load.
Other task execution runtimes provide static access to spawning tasks (i.e. `tokio::spawn`), which is notably easier to use than the reference passing required by `bevy_tasks` right now.
This PR makes does the following:
* Adds `*TaskPool::init` which initializes a `OnceCell`'ed with a provided TaskPool. Failing if the pool has already been initialized.
* Adds `*TaskPool::get` which fetches the initialized global pool of the respective type or panics. This generally should not be an issue in normal Bevy use, as the pools are initialized before they are accessed.
* Updated default task pool initialization to either pull the global handles and save them as resources, or if they are already initialized, pull the a cloned global handle as the resource.
This should make it notably easier to build more complex task hierarchies for dependent tasks. It should also make writing bevy-adjacent, but not strictly bevy-only plugin crates easier, as the global pools ensure it's all running on the same threads.
One alternative considered is keeping a thread-local reference to the pool for all threads in each pool to enable the same `tokio::spawn` interface. This would spawn tasks on the same pool that a task is currently running in. However this potentially leads to potential footgun situations where long running blocking tasks run on `ComputeTaskPool`.
2022-06-09 02:43:24 +00:00
|
|
|
fn spawn_tasks(mut commands: Commands) {
|
|
|
|
let thread_pool = AsyncComputeTaskPool::get();
|
2021-05-23 20:13:55 +00:00
|
|
|
for x in 0..NUM_CUBES {
|
|
|
|
for y in 0..NUM_CUBES {
|
|
|
|
for z in 0..NUM_CUBES {
|
2023-08-11 21:07:28 +00:00
|
|
|
// Spawn new task on the AsyncComputeTaskPool; the task will be
|
|
|
|
// executed in the background, and the Task future returned by
|
|
|
|
// spawn() can be used to poll for the result
|
2023-11-22 00:04:37 +00:00
|
|
|
let entity = commands.spawn_empty().id();
|
2021-05-23 20:13:55 +00:00
|
|
|
let task = thread_pool.spawn(async move {
|
|
|
|
let mut rng = rand::thread_rng();
|
2024-02-14 02:29:26 +00:00
|
|
|
|
2021-05-23 20:13:55 +00:00
|
|
|
let duration = Duration::from_secs_f32(rng.gen_range(0.05..0.2));
|
2024-02-14 02:29:26 +00:00
|
|
|
|
|
|
|
// Pretend this is a time-intensive function. :)
|
|
|
|
thread::sleep(duration);
|
2021-05-23 20:13:55 +00:00
|
|
|
|
|
|
|
// Such hard work, all done!
|
2023-11-22 00:04:37 +00:00
|
|
|
let transform = Transform::from_xyz(x as f32, y as f32, z as f32);
|
|
|
|
let mut command_queue = CommandQueue::default();
|
|
|
|
|
|
|
|
// we use a raw command queue to pass a FnOne(&mut World) back to be
|
|
|
|
// applied in a deferred manner.
|
|
|
|
command_queue.push(move |world: &mut World| {
|
|
|
|
let (box_mesh_handle, box_material_handle) = {
|
|
|
|
let mut system_state = SystemState::<(
|
|
|
|
Res<BoxMeshHandle>,
|
|
|
|
Res<BoxMaterialHandle>,
|
|
|
|
)>::new(world);
|
|
|
|
let (box_mesh_handle, box_material_handle) =
|
|
|
|
system_state.get_mut(world);
|
|
|
|
|
|
|
|
(box_mesh_handle.clone(), box_material_handle.clone())
|
|
|
|
};
|
|
|
|
|
|
|
|
world
|
|
|
|
.entity_mut(entity)
|
|
|
|
// Add our new PbrBundle of components to our tagged entity
|
|
|
|
.insert(PbrBundle {
|
|
|
|
mesh: box_mesh_handle,
|
|
|
|
material: box_material_handle,
|
|
|
|
transform,
|
|
|
|
..default()
|
|
|
|
})
|
|
|
|
// Task is complete, so remove task component from entity
|
|
|
|
.remove::<ComputeTransform>();
|
|
|
|
});
|
|
|
|
|
|
|
|
command_queue
|
2021-05-23 20:13:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Spawn new entity and add our new task as a component
|
2023-11-22 00:04:37 +00:00
|
|
|
commands.entity(entity).insert(ComputeTransform(task));
|
2021-05-23 20:13:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This system queries for entities that have our Task<Transform> component. It polls the
|
|
|
|
/// tasks to see if they're complete. If the task is complete it takes the result, adds a
|
2021-12-29 17:25:34 +00:00
|
|
|
/// new [`PbrBundle`] of components to the entity using the result from the task's work, and
|
2021-05-23 20:13:55 +00:00
|
|
|
/// removes the task component from the entity.
|
2023-11-22 00:04:37 +00:00
|
|
|
fn handle_tasks(mut commands: Commands, mut transform_tasks: Query<&mut ComputeTransform>) {
|
|
|
|
for mut task in &mut transform_tasks {
|
|
|
|
if let Some(mut commands_queue) = block_on(future::poll_once(&mut task.0)) {
|
|
|
|
// append the returned command queue to have it execute later
|
|
|
|
commands.append(&mut commands_queue);
|
2021-05-23 20:13:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This system is only used to setup light and camera for the environment
|
|
|
|
fn setup_env(mut commands: Commands) {
|
|
|
|
// Used to center camera on spawned cubes
|
|
|
|
let offset = if NUM_CUBES % 2 == 0 {
|
|
|
|
(NUM_CUBES / 2) as f32 - 0.5
|
|
|
|
} else {
|
|
|
|
(NUM_CUBES / 2) as f32
|
|
|
|
};
|
|
|
|
|
|
|
|
// lights
|
Spawn now takes a Bundle (#6054)
# Objective
Now that we can consolidate Bundles and Components under a single insert (thanks to #2975 and #6039), almost 100% of world spawns now look like `world.spawn().insert((Some, Tuple, Here))`. Spawning an entity without any components is an extremely uncommon pattern, so it makes sense to give spawn the "first class" ergonomic api. This consolidated api should be made consistent across all spawn apis (such as World and Commands).
## Solution
All `spawn` apis (`World::spawn`, `Commands:;spawn`, `ChildBuilder::spawn`, and `WorldChildBuilder::spawn`) now accept a bundle as input:
```rust
// before:
commands
.spawn()
.insert((A, B, C));
world
.spawn()
.insert((A, B, C);
// after
commands.spawn((A, B, C));
world.spawn((A, B, C));
```
All existing instances of `spawn_bundle` have been deprecated in favor of the new `spawn` api. A new `spawn_empty` has been added, replacing the old `spawn` api.
By allowing `world.spawn(some_bundle)` to replace `world.spawn().insert(some_bundle)`, this opened the door to removing the initial entity allocation in the "empty" archetype / table done in `spawn()` (and subsequent move to the actual archetype in `.insert(some_bundle)`).
This improves spawn performance by over 10%:
![image](https://user-images.githubusercontent.com/2694663/191627587-4ab2f949-4ccd-4231-80eb-80dd4d9ad6b9.png)
To take this measurement, I added a new `world_spawn` benchmark.
Unfortunately, optimizing `Commands::spawn` is slightly less trivial, as Commands expose the Entity id of spawned entities prior to actually spawning. Doing the optimization would (naively) require assurances that the `spawn(some_bundle)` command is applied before all other commands involving the entity (which would not necessarily be true, if memory serves). Optimizing `Commands::spawn` this way does feel possible, but it will require careful thought (and maybe some additional checks), which deserves its own PR. For now, it has the same performance characteristics of the current `Commands::spawn_bundle` on main.
**Note that 99% of this PR is simple renames and refactors. The only code that needs careful scrutiny is the new `World::spawn()` impl, which is relatively straightforward, but it has some new unsafe code (which re-uses battle tested BundlerSpawner code path).**
---
## Changelog
- All `spawn` apis (`World::spawn`, `Commands:;spawn`, `ChildBuilder::spawn`, and `WorldChildBuilder::spawn`) now accept a bundle as input
- All instances of `spawn_bundle` have been deprecated in favor of the new `spawn` api
- World and Commands now have `spawn_empty()`, which is equivalent to the old `spawn()` behavior.
## Migration Guide
```rust
// Old (0.8):
commands
.spawn()
.insert_bundle((A, B, C));
// New (0.9)
commands.spawn((A, B, C));
// Old (0.8):
commands.spawn_bundle((A, B, C));
// New (0.9)
commands.spawn((A, B, C));
// Old (0.8):
let entity = commands.spawn().id();
// New (0.9)
let entity = commands.spawn_empty().id();
// Old (0.8)
let entity = world.spawn().id();
// New (0.9)
let entity = world.spawn_empty();
```
2022-09-23 19:55:54 +00:00
|
|
|
commands.spawn(PointLightBundle {
|
2022-02-06 01:07:55 +00:00
|
|
|
transform: Transform::from_xyz(4.0, 12.0, 15.0),
|
2022-03-01 20:52:09 +00:00
|
|
|
..default()
|
2021-05-23 20:13:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// camera
|
Spawn now takes a Bundle (#6054)
# Objective
Now that we can consolidate Bundles and Components under a single insert (thanks to #2975 and #6039), almost 100% of world spawns now look like `world.spawn().insert((Some, Tuple, Here))`. Spawning an entity without any components is an extremely uncommon pattern, so it makes sense to give spawn the "first class" ergonomic api. This consolidated api should be made consistent across all spawn apis (such as World and Commands).
## Solution
All `spawn` apis (`World::spawn`, `Commands:;spawn`, `ChildBuilder::spawn`, and `WorldChildBuilder::spawn`) now accept a bundle as input:
```rust
// before:
commands
.spawn()
.insert((A, B, C));
world
.spawn()
.insert((A, B, C);
// after
commands.spawn((A, B, C));
world.spawn((A, B, C));
```
All existing instances of `spawn_bundle` have been deprecated in favor of the new `spawn` api. A new `spawn_empty` has been added, replacing the old `spawn` api.
By allowing `world.spawn(some_bundle)` to replace `world.spawn().insert(some_bundle)`, this opened the door to removing the initial entity allocation in the "empty" archetype / table done in `spawn()` (and subsequent move to the actual archetype in `.insert(some_bundle)`).
This improves spawn performance by over 10%:
![image](https://user-images.githubusercontent.com/2694663/191627587-4ab2f949-4ccd-4231-80eb-80dd4d9ad6b9.png)
To take this measurement, I added a new `world_spawn` benchmark.
Unfortunately, optimizing `Commands::spawn` is slightly less trivial, as Commands expose the Entity id of spawned entities prior to actually spawning. Doing the optimization would (naively) require assurances that the `spawn(some_bundle)` command is applied before all other commands involving the entity (which would not necessarily be true, if memory serves). Optimizing `Commands::spawn` this way does feel possible, but it will require careful thought (and maybe some additional checks), which deserves its own PR. For now, it has the same performance characteristics of the current `Commands::spawn_bundle` on main.
**Note that 99% of this PR is simple renames and refactors. The only code that needs careful scrutiny is the new `World::spawn()` impl, which is relatively straightforward, but it has some new unsafe code (which re-uses battle tested BundlerSpawner code path).**
---
## Changelog
- All `spawn` apis (`World::spawn`, `Commands:;spawn`, `ChildBuilder::spawn`, and `WorldChildBuilder::spawn`) now accept a bundle as input
- All instances of `spawn_bundle` have been deprecated in favor of the new `spawn` api
- World and Commands now have `spawn_empty()`, which is equivalent to the old `spawn()` behavior.
## Migration Guide
```rust
// Old (0.8):
commands
.spawn()
.insert_bundle((A, B, C));
// New (0.9)
commands.spawn((A, B, C));
// Old (0.8):
commands.spawn_bundle((A, B, C));
// New (0.9)
commands.spawn((A, B, C));
// Old (0.8):
let entity = commands.spawn().id();
// New (0.9)
let entity = commands.spawn_empty().id();
// Old (0.8)
let entity = world.spawn().id();
// New (0.9)
let entity = world.spawn_empty();
```
2022-09-23 19:55:54 +00:00
|
|
|
commands.spawn(Camera3dBundle {
|
2022-02-06 01:07:55 +00:00
|
|
|
transform: Transform::from_xyz(offset, offset, 15.0)
|
2021-05-23 20:13:55 +00:00
|
|
|
.looking_at(Vec3::new(offset, offset, 0.0), Vec3::Y),
|
2022-03-01 20:52:09 +00:00
|
|
|
..default()
|
2021-05-23 20:13:55 +00:00
|
|
|
});
|
|
|
|
}
|