pub trait CommandsSceneExt {
// Required methods
fn spawn_scene<S>(&mut self, scene: S) -> EntityCommands<'_>
where S: Scene;
fn queue_spawn_scene<S>(&mut self, scene: S) -> EntityCommands<'_>
where S: Scene;
fn spawn_scene_list<L>(&mut self, scenes: L)
where L: SceneList;
fn queue_spawn_scene_list<L>(&mut self, scenes: L)
where L: SceneList;
}Expand description
Adds scene spawning functionality to Commands.
Required Methods§
Sourcefn spawn_scene<S>(&mut self, scene: S) -> EntityCommands<'_>where
S: Scene,
fn spawn_scene<S>(&mut self, scene: S) -> EntityCommands<'_>where
S: Scene,
Spawns the given Scene as soon as Commands are applied. This will resolve the Scene (using Scene::resolve). If that fails (for example, if there are dependencies that have not been
loaded yet), it will log a SpawnSceneError as an error. If resolving the Scene is successful, the scene will be spawned.
This is essentially a Command that runs World::spawn_scene.
See Scene for the features of the scene system (and how to use it).
If your scene has a dependency that might not be loaded yet (for example, it includes a .bsn asset file), consider using Commands::queue_spawn_scene.
Note that the .bsn file format is not yet released.
#[derive(Component, Default, Clone)]
struct Score(usize);
#[derive(Component, Default, Clone)]
struct Sword;
#[derive(Component, Default, Clone)]
struct Shield;
commands.spawn_scene(bsn! {
#Player
Score(0)
Children [
Sword,
Shield,
]
});Sourcefn queue_spawn_scene<S>(&mut self, scene: S) -> EntityCommands<'_>where
S: Scene,
fn queue_spawn_scene<S>(&mut self, scene: S) -> EntityCommands<'_>where
S: Scene,
Queues the scene to be spawned. This will evaluate the scene’s dependencies (via Scene::register_dependencies) and queue it to be resolved and spawned
after all of the dependencies have been loaded. If a SpawnSceneError occurs, it will be logged as an error.
If the dependencies are already loaded (or there are no dependencies), then the scene will be spawned this frame.
See Scene for the features of the scene system (and how to use it).
#[derive(Component, Default, Clone)]
struct Score(usize);
#[derive(Component, Default, Clone)]
struct Sword;
#[derive(Component, Default, Clone)]
struct Shield;
// This scene includes the "player.bsn" asset (note that the `.bsn` file format is not yet released). It will be spawned on the frame that "player.bsn"
// is fully loaded.
commands.queue_spawn_scene(bsn! {
:"player.bsn"
#Player
Score(0)
Children [
Sword,
Shield,
]
});Sourcefn spawn_scene_list<L>(&mut self, scenes: L)where
L: SceneList,
fn spawn_scene_list<L>(&mut self, scenes: L)where
L: SceneList,
Spawns the given SceneList as soon as Commands are applied. This will resolve the scene list (using SceneList::resolve_list). If that fails (for example, if there are dependencies that have not been
loaded yet), it will log a SpawnSceneError as an error. If resolving the Scene is successful, the scene list will be spawned.
This is essentially a Command that performs World::spawn_scene_list.
See Scene for the features of the scene system (and how to use it).
If your scene list has a dependency that might not be loaded yet (for example, it includes a .bsn asset file), consider using Commands::queue_spawn_scene_list.
#[derive(Component, FromTemplate)]
enum Team {
#[default]
Red,
Blue,
}
// Note that the .bsn file format is not yet released.
commands.spawn_scene_list(bsn_list! {
(
:"player.bsn"
#Player1
Team::Red
),
(
:"player.bsn"
#Player2
Team::Blue
)
});Sourcefn queue_spawn_scene_list<L>(&mut self, scenes: L)where
L: SceneList,
fn queue_spawn_scene_list<L>(&mut self, scenes: L)where
L: SceneList,
Queues the scene_list to be spawned. This will evaluate the scene_list’s dependencies (via Scene::register_dependencies) and queue it to be resolved
and spawned after all of the dependencies have been loaded. If a SpawnSceneError occurs, it will be logged as an error.
If the dependencies are already loaded (or there are no dependencies), then the scene will be spawned this frame.
#[derive(Component, FromTemplate)]
enum Team {
#[default]
Red,
Blue,
}
// This scene list includes the "player.bsn" asset (note that the `.bsn` file format is not yet released). It will be spawned on the frame that "player.bsn"
// is loaded.
commands.queue_spawn_scene_list(bsn_list! [
(
:"player.bsn"
#Player1
Team::Red
),
(
:"player.bsn"
#Player2
Team::Blue
)
]);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".