diff --git a/crates/bevy_mod_scripting_core/src/commands.rs b/crates/bevy_mod_scripting_core/src/commands.rs index 57b37195a9..624fb790bc 100644 --- a/crates/bevy_mod_scripting_core/src/commands.rs +++ b/crates/bevy_mod_scripting_core/src/commands.rs @@ -315,6 +315,7 @@ impl Command for RunScriptCallback

{ send_callback_response( guard.clone(), ScriptCallbackResponseEvent::new( + self.entity, self.callback, self.id.clone(), result.clone(), @@ -569,6 +570,7 @@ mod test { assert_response_events( app.world_mut(), vec![ScriptCallbackResponseEvent::new( + Entity::from_raw(0), OnScriptLoaded::into_callback_label(), "script".into(), Ok(ScriptValue::Unit), diff --git a/crates/bevy_mod_scripting_core/src/event.rs b/crates/bevy_mod_scripting_core/src/event.rs index 7d9c5c3da7..2661415bba 100644 --- a/crates/bevy_mod_scripting_core/src/event.rs +++ b/crates/bevy_mod_scripting_core/src/event.rs @@ -173,6 +173,8 @@ impl ScriptCallbackEvent { #[derive(Clone, Event, Debug)] #[non_exhaustive] pub struct ScriptCallbackResponseEvent { + /// the entity that the script was invoked on, + pub entity: Entity, /// the label of the callback pub label: CallbackLabel, /// the script that replied @@ -184,11 +186,13 @@ pub struct ScriptCallbackResponseEvent { impl ScriptCallbackResponseEvent { /// Creates a new callback response event with the given label, script and response pub fn new>( + entity: Entity, label: L, script: ScriptId, response: Result, ) -> Self { Self { + entity, label: label.into(), script, response, diff --git a/crates/bevy_mod_scripting_core/src/handler.rs b/crates/bevy_mod_scripting_core/src/handler.rs index 34f259c4c7..322ea6adfb 100644 --- a/crates/bevy_mod_scripting_core/src/handler.rs +++ b/crates/bevy_mod_scripting_core/src/handler.rs @@ -207,6 +207,7 @@ pub(crate) fn event_handler_inner( send_callback_response( guard.clone(), ScriptCallbackResponseEvent::new( + *entity, callback_label.clone(), script_id.clone(), call_result.clone(), @@ -384,8 +385,10 @@ mod test { invocations: vec![].into(), }; let mut app = setup_app::(runtime, scripts); - app.world_mut() - .spawn(ScriptComponent(vec![test_script_id.clone()])); + let entity = app + .world_mut() + .spawn(ScriptComponent(vec![test_script_id.clone()])) + .id(); app.world_mut().send_event( ScriptCallbackEvent::new( @@ -400,6 +403,7 @@ mod test { assert_response_events( app.world_mut(), vec![ScriptCallbackResponseEvent::new( + entity, OnTestCallback::into_callback_label(), test_script_id.clone(), Ok(ScriptValue::Unit),