Skip to content

Commit 48d10e6

Browse files
authored
Use handles for queued scenes in SceneSpawner (#10619)
# Objective Fixes #10482 ## Solution Store Handles instead of AssetIds for queued Scenes and DynamicScenes in SceneSpawner.
1 parent 1d3ae67 commit 48d10e6

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

crates/bevy_scene/src/scene_spawner.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{DynamicScene, Scene};
2-
use bevy_asset::{AssetEvent, AssetId, Assets};
2+
use bevy_asset::{AssetEvent, AssetId, Assets, Handle};
33
use bevy_ecs::{
44
entity::Entity,
55
event::{Event, Events, ManualEventReader},
@@ -63,8 +63,8 @@ pub struct SceneSpawner {
6363
spawned_dynamic_scenes: HashMap<AssetId<DynamicScene>, Vec<InstanceId>>,
6464
spawned_instances: HashMap<InstanceId, InstanceInfo>,
6565
scene_asset_event_reader: ManualEventReader<AssetEvent<DynamicScene>>,
66-
dynamic_scenes_to_spawn: Vec<(AssetId<DynamicScene>, InstanceId)>,
67-
scenes_to_spawn: Vec<(AssetId<Scene>, InstanceId)>,
66+
dynamic_scenes_to_spawn: Vec<(Handle<DynamicScene>, InstanceId)>,
67+
scenes_to_spawn: Vec<(Handle<Scene>, InstanceId)>,
6868
scenes_to_despawn: Vec<AssetId<DynamicScene>>,
6969
instances_to_despawn: Vec<InstanceId>,
7070
scenes_with_parent: Vec<(InstanceId, Entity)>,
@@ -127,7 +127,7 @@ pub enum SceneSpawnError {
127127

128128
impl SceneSpawner {
129129
/// Schedule the spawn of a new instance of the provided dynamic scene.
130-
pub fn spawn_dynamic(&mut self, id: impl Into<AssetId<DynamicScene>>) -> InstanceId {
130+
pub fn spawn_dynamic(&mut self, id: impl Into<Handle<DynamicScene>>) -> InstanceId {
131131
let instance_id = InstanceId::new();
132132
self.dynamic_scenes_to_spawn.push((id.into(), instance_id));
133133
instance_id
@@ -136,7 +136,7 @@ impl SceneSpawner {
136136
/// Schedule the spawn of a new instance of the provided dynamic scene as a child of `parent`.
137137
pub fn spawn_dynamic_as_child(
138138
&mut self,
139-
id: impl Into<AssetId<DynamicScene>>,
139+
id: impl Into<Handle<DynamicScene>>,
140140
parent: Entity,
141141
) -> InstanceId {
142142
let instance_id = InstanceId::new();
@@ -146,14 +146,14 @@ impl SceneSpawner {
146146
}
147147

148148
/// Schedule the spawn of a new instance of the provided scene.
149-
pub fn spawn(&mut self, id: impl Into<AssetId<Scene>>) -> InstanceId {
149+
pub fn spawn(&mut self, id: impl Into<Handle<Scene>>) -> InstanceId {
150150
let instance_id = InstanceId::new();
151151
self.scenes_to_spawn.push((id.into(), instance_id));
152152
instance_id
153153
}
154154

155155
/// Schedule the spawn of a new instance of the provided scene as a child of `parent`.
156-
pub fn spawn_as_child(&mut self, id: impl Into<AssetId<Scene>>, parent: Entity) -> InstanceId {
156+
pub fn spawn_as_child(&mut self, id: impl Into<Handle<Scene>>, parent: Entity) -> InstanceId {
157157
let instance_id = InstanceId::new();
158158
self.scenes_to_spawn.push((id.into(), instance_id));
159159
self.scenes_with_parent.push((instance_id, parent));
@@ -296,21 +296,21 @@ impl SceneSpawner {
296296
pub fn spawn_queued_scenes(&mut self, world: &mut World) -> Result<(), SceneSpawnError> {
297297
let scenes_to_spawn = std::mem::take(&mut self.dynamic_scenes_to_spawn);
298298

299-
for (id, instance_id) in scenes_to_spawn {
299+
for (handle, instance_id) in scenes_to_spawn {
300300
let mut entity_map = EntityHashMap::default();
301301

302-
match Self::spawn_dynamic_internal(world, id, &mut entity_map) {
302+
match Self::spawn_dynamic_internal(world, handle.id(), &mut entity_map) {
303303
Ok(_) => {
304304
self.spawned_instances
305305
.insert(instance_id, InstanceInfo { entity_map });
306306
let spawned = self
307307
.spawned_dynamic_scenes
308-
.entry(id)
308+
.entry(handle.id())
309309
.or_insert_with(Vec::new);
310310
spawned.push(instance_id);
311311
}
312312
Err(SceneSpawnError::NonExistentScene { .. }) => {
313-
self.dynamic_scenes_to_spawn.push((id, instance_id));
313+
self.dynamic_scenes_to_spawn.push((handle, instance_id));
314314
}
315315
Err(err) => return Err(err),
316316
}
@@ -319,10 +319,10 @@ impl SceneSpawner {
319319
let scenes_to_spawn = std::mem::take(&mut self.scenes_to_spawn);
320320

321321
for (scene_handle, instance_id) in scenes_to_spawn {
322-
match self.spawn_sync_internal(world, scene_handle, instance_id) {
322+
match self.spawn_sync_internal(world, scene_handle.id(), instance_id) {
323323
Ok(_) => {}
324-
Err(SceneSpawnError::NonExistentRealScene { id: handle }) => {
325-
self.scenes_to_spawn.push((handle, instance_id));
324+
Err(SceneSpawnError::NonExistentRealScene { .. }) => {
325+
self.scenes_to_spawn.push((scene_handle, instance_id));
326326
}
327327
Err(err) => return Err(err),
328328
}

0 commit comments

Comments
 (0)