Repository: bevyengine/bevy
File: crates/bevy_scene/src/scene_spawner.rs (Rust)

Code before:
/// - [`update_spawned_scenes`](Self::update_spawned_scenes)
/// - [`update_spawned_dynamic_scenes`](Self::update_spawned_dynamic_scenes)
/// - [`spawn_queued_scenes`](Self::spawn_queued_scenes)
/// - [`despawn_queued_scenes`](Self::despawn_queued_scenes)
/// - [`despawn_queued_instances`](Self::despawn_queued_instances)
///
/// Deferred methods: (Scene operations will be processed when the [`scene_spawner_system`] is run)
/// - [`spawn_dynamic`](Self::spawn_dynamic)
/// - [`spawn_dynamic_as_child`](Self::spawn_dynamic_as_child)
/// - [`spawn`](Self::spawn)
/// - [`spawn_as_child`](Self::spawn_as_child)
/// - [`despawn`](Self::despawn)
/// - [`despawn_dynamic`](Self::despawn_dynamic)
/// - [`despawn_instance`](Self::despawn_instance)
#[derive(Default, Resource)]
pub struct SceneSpawner {
    pub(crate) spawned_scenes: HashMap<AssetId<Scene>, HashSet<InstanceId>>,
    pub(crate) spawned_dynamic_scenes: HashMap<AssetId<DynamicScene>, HashSet<InstanceId>>,
    spawned_instances: HashMap<InstanceId, InstanceInfo>,
    scene_asset_event_reader: EventCursor<AssetEvent<Scene>>,
    // TODO: temp fix for https://github.com/bevyengine/bevy/issues/12756 effect on scenes
    // To handle scene hot reloading, they are unloaded/reloaded on asset modifications.
    // When loading several subassets of a scene as is common with gltf, they each trigger a complete asset load,
    // and each will trigger either a created or modified event for the parent asset. This causes the scene to be
    // unloaded, losing its initial setup, and reloaded without it.
    // Debouncing scene asset events let us ignore events that happens less than SCENE_ASSET_AGE_THRESHOLD frames
    // apart and not reload the scene in those cases as it's unlikely to be an actual asset change.
    debounced_scene_asset_events: HashMap<AssetId<Scene>, u32>,
    dynamic_scene_asset_event_reader: EventCursor<AssetEvent<DynamicScene>>,
    // TODO: temp fix for https://github.com/bevyengine/bevy/issues/12756 effect on scenes
    // See debounced_scene_asset_events
    debounced_dynamic_scene_asset_events: HashMap<AssetId<DynamicScene>, u32>,
    scenes_to_spawn: Vec<(Handle<Scene>, InstanceId, Option<Entity>)>,
    dynamic_scenes_to_spawn: Vec<(Handle<DynamicScene>, InstanceId, Option<Entity>)>,
    scenes_to_despawn: Vec<AssetId<Scene>>,
    dynamic_scenes_to_despawn: Vec<AssetId<DynamicScene>>,
    instances_to_despawn: Vec<InstanceId>,
    instances_ready: Vec<(InstanceId, Option<Entity>)>,
}

/// Errors that can occur when spawning a scene.
#[derive(Error, Debug)]
pub enum SceneSpawnError {
    /// Scene contains an unregistered component type.
    #[error("scene contains the unregistered component `{type_path}`. consider adding `#[reflect(Component)]` to your type")]
    UnregisteredComponent {
        /// Type of the unregistered component.
        type_path: String,
    },
    /// Scene contains an unregistered resource type.
    #[error("scene contains the unregistered resource `{type_path}`. consider adding `#[reflect(Resource)]` to your type")]

Review comment (suggestion):
```suggestion
    // Debouncing scene asset events let us ignore events that happen less than SCENE_ASSET_AGE_THRESHOLD frames
```

More English for you.

Code after:
/// - [`update_spawned_scenes`](Self::update_spawned_scenes)
/// - [`update_spawned_dynamic_scenes`](Self::update_spawned_dynamic_scenes)
/// - [`spawn_queued_scenes`](Self::spawn_queued_scenes)
/// - [`despawn_queued_scenes`](Self::despawn_queued_scenes)
/// - [`despawn_queued_instances`](Self::despawn_queued_instances)
///
/// Deferred methods: (Scene operations will be processed when the [`scene_spawner_system`] is run)
/// - [`spawn_dynamic`](Self::spawn_dynamic)
/// - [`spawn_dynamic_as_child`](Self::spawn_dynamic_as_child)
/// - [`spawn`](Self::spawn)
/// - [`spawn_as_child`](Self::spawn_as_child)
/// - [`despawn`](Self::despawn)
/// - [`despawn_dynamic`](Self::despawn_dynamic)
/// - [`despawn_instance`](Self::despawn_instance)
#[derive(Default, Resource)]
pub struct SceneSpawner {
    pub(crate) spawned_scenes: HashMap<AssetId<Scene>, HashSet<InstanceId>>,
    pub(crate) spawned_dynamic_scenes: HashMap<AssetId<DynamicScene>, HashSet<InstanceId>>,
    spawned_instances: HashMap<InstanceId, InstanceInfo>,
    scene_asset_event_reader: EventCursor<AssetEvent<Scene>>,
    // TODO: temp fix for https://github.com/bevyengine/bevy/issues/12756 effect on scenes
    // To handle scene hot reloading, they are unloaded/reloaded on asset modifications.
    // When loading several subassets of a scene as is common with gltf, they each trigger a complete asset load,
    // and each will trigger either a created or modified event for the parent asset. This causes the scene to be
    // unloaded, losing its initial setup, and reloaded without it.
    // Debouncing scene asset events let us ignore events that happen less than SCENE_ASSET_AGE_THRESHOLD frames
    // apart and not reload the scene in those cases as it's unlikely to be an actual asset change.
    debounced_scene_asset_events: HashMap<AssetId<Scene>, u32>,
    dynamic_scene_asset_event_reader: EventCursor<AssetEvent<DynamicScene>>,
    // TODO: temp fix for https://github.com/bevyengine/bevy/issues/12756 effect on scenes
    // See debounced_scene_asset_events
    debounced_dynamic_scene_asset_events: HashMap<AssetId<DynamicScene>, u32>,
    scenes_to_spawn: Vec<(Handle<Scene>, InstanceId, Option<Entity>)>,
    dynamic_scenes_to_spawn: Vec<(Handle<DynamicScene>, InstanceId, Option<Entity>)>,
    scenes_to_despawn: Vec<AssetId<Scene>>,
    dynamic_scenes_to_despawn: Vec<AssetId<DynamicScene>>,
    instances_to_despawn: Vec<InstanceId>,
    instances_ready: Vec<(InstanceId, Option<Entity>)>,
}

/// Errors that can occur when spawning a scene.
#[derive(Error, Debug)]
pub enum SceneSpawnError {
    /// Scene contains an unregistered component type.
    #[error("scene contains the unregistered component `{type_path}`. consider adding `#[reflect(Component)]` to your type")]
    UnregisteredComponent {
        /// Type of the unregistered component.
        type_path: String,
    },
    /// Scene contains an unregistered resource type.
    #[error("scene contains the unregistered resource `{type_path}`. consider adding `#[reflect(Resource)]` to your type")]