Skip to content

Commit 864bb52

Browse files
committed
correct script unloading handling
1 parent 12a2661 commit 864bb52

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

crates/bevy_mod_scripting_core/src/asset.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,20 @@ pub(crate) fn sync_script_data<P: IntoScriptPluginParams>(
252252
mut commands: Commands,
253253
) {
254254
for event in events.read() {
255+
let metadata = match event {
256+
ScriptAssetEvent::Added(script_metadata)
257+
| ScriptAssetEvent::Removed(script_metadata)
258+
| ScriptAssetEvent::Modified(script_metadata) => script_metadata,
259+
};
260+
261+
if metadata.language != P::LANGUAGE {
262+
continue;
263+
}
264+
255265
trace!("{}: Received script asset event: {:?}", P::LANGUAGE, event);
256266
match event {
257267
// emitted when a new script asset is loaded for the first time
258-
ScriptAssetEvent::Added(metadata) | ScriptAssetEvent::Modified(metadata) => {
268+
ScriptAssetEvent::Added(_) | ScriptAssetEvent::Modified(_) => {
259269
if metadata.language != P::LANGUAGE {
260270
trace!(
261271
"{}: Script asset with id: {} is for a different langauge than this sync system. Skipping.",
@@ -275,7 +285,7 @@ pub(crate) fn sync_script_data<P: IntoScriptPluginParams>(
275285
));
276286
}
277287
}
278-
ScriptAssetEvent::Removed(metadata) => {
288+
ScriptAssetEvent::Removed(_) => {
279289
info!("{}: Deleting Script: {:?}", P::LANGUAGE, metadata.script_id,);
280290
commands.queue(DeleteScript::<P>::new(metadata.script_id.clone()));
281291
}

crates/bevy_mod_scripting_core/src/handler.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use bevy::{
1616
system::{Resource, SystemState},
1717
world::World,
1818
},
19-
log::trace,
19+
log::{trace, trace_once},
2020
prelude::{EventReader, Events, Query, Ref},
2121
};
2222

@@ -127,17 +127,11 @@ pub(crate) fn event_handler_internal<L: IntoCallbackLabel, P: IntoScriptPluginPa
127127
}
128128
_ => (),
129129
}
130-
trace!(
131-
"{}: Handling event for script {} on entity {:?}",
132-
P::LANGUAGE,
133-
script_id,
134-
entity
135-
);
136130
let script = match res_ctxt.scripts.scripts.get(script_id) {
137131
Some(s) => s,
138132
None => {
139-
trace!(
140-
"{}: Script `{}` on entity `{:?}` is either still loading or doesn't exist, ignoring.",
133+
trace_once!(
134+
"{}: Script `{}` on entity `{:?}` is either still loading or doesn't exist, ignoring until the corresponding script is loaded.",
141135
P::LANGUAGE,
142136
script_id, entity
143137
);

0 commit comments

Comments
 (0)