@@ -38,12 +38,10 @@ impl StrongScriptHandle {
3838 handle : Handle < ScriptAsset > ,
3939 assets : & mut Assets < ScriptAsset > ,
4040 ) -> Option < Self > {
41- assets. get_strong_handle ( handle. id ( ) ) . map ( Self )
42- }
43-
44- /// Upgrades an asset Id pointing to a script to a strong handle if the asset hasn't been dropped
45- pub fn upgrade ( id : ScriptId , assets : & mut Assets < ScriptAsset > ) -> Option < Self > {
46- assets. get_strong_handle ( id) . map ( Self )
41+ match handle {
42+ s @ Handle :: Strong ( _) => Some ( Self ( s) ) ,
43+ _ => assets. get_strong_handle ( handle. id ( ) ) . map ( Self ) ,
44+ }
4745 }
4846
4947 /// Returns a reference to the strong handle inside
@@ -122,12 +120,14 @@ pub fn process_attachments<P: IntoScriptPluginParams>(
122120 let contexts = contexts. read ( ) ;
123121 events. read ( ) . for_each ( |wrapper| {
124122 let attachment_event = wrapper. event ( ) ;
125- let id = attachment_event. 0 . script ( ) . id ( ) ;
126- let context = Context {
123+ let id = attachment_event. 0 . script ( ) ;
124+ let mut context = Context {
127125 attachment : attachment_event. 0 . clone ( ) ,
128126 blackboard : Default :: default ( ) ,
129127 } ;
130- if let Some ( strong_handle) = StrongScriptHandle :: upgrade ( id, & mut assets) {
128+ if let Some ( strong_handle) = StrongScriptHandle :: from_assets ( id, & mut assets) {
129+ // we want the loading process to have access to asset paths, we will weaken the handle at the end.
130+ * context. attachment . script_mut ( ) = strong_handle. 0 . clone ( ) ;
131131 let content = strong_handle. get ( & assets) ;
132132 if let Some ( existing_context) = contexts. get_context ( & attachment_event. 0 ) {
133133 machines. queue_machine (
@@ -193,8 +193,8 @@ pub fn process_asset_modifications<P: IntoScriptPluginParams>(
193193 affected_attachments
194194 . into_iter ( )
195195 . for_each ( |( attachment, existing_context) | {
196- let id = attachment. script ( ) . id ( ) ;
197- if let Some ( strong_handle) = StrongScriptHandle :: upgrade ( id, & mut assets) {
196+ let id = attachment. script ( ) ;
197+ if let Some ( strong_handle) = StrongScriptHandle :: from_assets ( id, & mut assets) {
198198 let content = strong_handle. get ( & assets) ;
199199 machines. queue_machine (
200200 Context {
0 commit comments