diff --git a/assets/tests/handle/handle_asset_path_when_script_loaded.lua b/assets/tests/handle/handle_asset_path_when_script_loaded.lua index f0c5f301aa..dd3a289895 100644 --- a/assets/tests/handle/handle_asset_path_when_script_loaded.lua +++ b/assets/tests/handle/handle_asset_path_when_script_loaded.lua @@ -1,6 +1,10 @@ local expected_asset_path = "tests/handle/handle_asset_path_when_script_loaded.lua" function normalize_path(path) - return string.gsub(tostring(path), "\\", "/") + if path then + return string.gsub(path, "\\", "/") + else + return nil + end end local normalized_gotten_asset_path = normalize_path(script_asset:asset_path()) diff --git a/crates/bevy_mod_scripting_core/src/asset.rs b/crates/bevy_mod_scripting_core/src/asset.rs index 4e5f25f074..5c09fec0cf 100644 --- a/crates/bevy_mod_scripting_core/src/asset.rs +++ b/crates/bevy_mod_scripting_core/src/asset.rs @@ -12,7 +12,7 @@ use crate::{ }; use bevy::{ app::{App, Last}, - asset::{Asset, AssetEvent, AssetLoader, AssetPath, Assets, LoadState}, + asset::{Asset, AssetEvent, AssetLoader, Assets, LoadState}, log::{error, trace, warn, warn_once}, prelude::{ AssetServer, Commands, Entity, EventReader, EventWriter, IntoScheduleConfigs, Local, Query, @@ -59,8 +59,6 @@ pub struct ScriptAsset { pub content: Box<[u8]>, // Any chance a Cow<'static, ?> could work here? /// The language of the script pub language: Language, - /// The asset path of the script. - pub asset_path: AssetPath<'static>, } impl From for ScriptAsset { @@ -68,7 +66,6 @@ impl From for ScriptAsset { ScriptAsset { content: s.into_bytes().into_boxed_slice(), language: Language::default(), - asset_path: AssetPath::default(), } } } @@ -168,7 +165,6 @@ impl AssetLoader for ScriptAssetLoader { let asset = ScriptAsset { content: content.into_boxed_slice(), language, - asset_path: load_context.asset_path().clone(), }; Ok(asset) } diff --git a/crates/bevy_mod_scripting_functions/src/core.rs b/crates/bevy_mod_scripting_functions/src/core.rs index 9c0dfe2611..3904897bb6 100644 --- a/crates/bevy_mod_scripting_functions/src/core.rs +++ b/crates/bevy_mod_scripting_functions/src/core.rs @@ -1257,15 +1257,14 @@ impl Handle { /// * `path`: The asset path of the script asset. fn asset_path(ctxt: FunctionCallContext, handle: Ref>) -> Option { profiling::function_scope!("path"); - ctxt.world().ok().and_then(|w| { - w.with_resource(|assets: &Assets| { - // debug - assets - .get(&*handle) - .map(|asset| asset.asset_path.to_string()) + handle.path().map(|p| p.to_string()).or_else(|| { + ctxt.world().ok().and_then(|w| { + w.with_resource(|asset_server: &AssetServer| { + asset_server.get_path(&*handle).map(|p| p.to_string()) + }) + .ok() + .flatten() }) - .ok() - .flatten() }) } } diff --git a/crates/testing_crates/script_integration_test_harness/src/scenario.rs b/crates/testing_crates/script_integration_test_harness/src/scenario.rs index 1c5fa8a71f..c24a4e2b8e 100644 --- a/crates/testing_crates/script_integration_test_harness/src/scenario.rs +++ b/crates/testing_crates/script_integration_test_harness/src/scenario.rs @@ -700,7 +700,6 @@ impl ScenarioStep { let boxed_byte_arr = content.into_bytes().into_boxed_slice(); *existing = ScriptAsset { content: boxed_byte_arr, - asset_path: path.into(), language: existing.language.clone(), }; } else {