Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SceneInstanceReady #9313

Merged
merged 2 commits into from Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/bevy_scene/src/lib.rs
Expand Up @@ -39,6 +39,7 @@ impl Plugin for ScenePlugin {
app.add_asset::<DynamicScene>()
.add_asset::<Scene>()
.init_asset_loader::<SceneLoader>()
.add_event::<SceneInstanceReady>()
.init_resource::<SceneSpawner>()
.add_systems(Update, scene_spawner_system)
// Systems `*_bundle_spawner` must run before `scene_spawner_system`
Expand Down
13 changes: 12 additions & 1 deletion crates/bevy_scene/src/scene_spawner.rs
Expand Up @@ -2,7 +2,7 @@ use crate::{DynamicScene, Scene};
use bevy_asset::{AssetEvent, Assets, Handle};
use bevy_ecs::{
entity::{Entity, EntityMap},
event::{Events, ManualEventReader},
event::{Event, Events, ManualEventReader},
reflect::AppTypeRegistry,
system::{Command, Resource},
world::{Mut, World},
Expand All @@ -12,6 +12,15 @@ use bevy_utils::{tracing::error, HashMap, HashSet};
use thiserror::Error;
use uuid::Uuid;

/// Emitted when [`crate::SceneInstance`] becomes ready to use.
///
/// See also [`SceneSpawner::instance_is_ready`].
#[derive(Event)]
pub struct SceneInstanceReady {
/// Entity to which the scene was spawned as a child.
pub parent: Entity,
}

/// Information about a scene instance.
#[derive(Debug)]
pub struct InstanceInfo {
Expand Down Expand Up @@ -285,6 +294,8 @@ impl SceneSpawner {
child: entity,
}
.apply(world);

world.send_event(SceneInstanceReady { parent });
}
}
} else {
Expand Down