Skip to content

Commit 852ce00

Browse files
committed
dont error on deleting non existing script
1 parent 1ca419b commit 852ce00

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

crates/bevy_mod_scripting_core/src/commands.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,20 @@ impl<P: IntoScriptPluginParams> Command for DeleteScript<P> {
5656
// we demote to weak from here on out, so as not to hold the asset hostage
5757
self.context_key = self.context_key.into_weak();
5858

59-
// first apply unload callback
59+
// first check the script exists, if it does not it could have been deleted by another command
60+
{
61+
let script_contexts = world.get_resource_or_init::<ScriptContext<P>>();
62+
if !script_contexts.contains(&self.context_key) {
63+
debug!(
64+
"{}: No context found for {}, not deleting.",
65+
P::LANGUAGE,
66+
self.context_key
67+
);
68+
return;
69+
}
70+
}
71+
72+
// apply unload callback
6073
Command::apply(
6174
RunScriptCallback::<P>::new(
6275
self.context_key.clone(),

0 commit comments

Comments
 (0)