Repository navigation
|
I have been wondering about the most idiomatic way to store a script in memory and occasionally trigger it. I'm slightly confused by the documentation and have found myself creating this system to get started: callback_labels!(
Run => "run",
);
pub fn register_script(asset_server: Res<AssetServer>, mut scripts: ResMut<resources::MobileScripts>) {
let script = r#"
print("script successfully loaded");
function run()
print("it works!")
end
"#;
let script = script.as_bytes().to_owned().into_boxed_slice();
let script_id = 12345;
let path = AssetPath::parse(&format!("mem:://entity-name/entity-1234/{script_id}.lua"));
let asset = ScriptAsset {
content: script.clone(),
asset_path,
};
let handle: bevy::asset::Handle<ScriptAsset> = asset_server.add(asset);
scripts.inner.insert(script_id, handle.clone());
CreateOrUpdateScript::<LuaScriptingPlugin>::new(path.into(), script, None);
}I can't help but think that this is the wrong way to do it. Is there a simpler path? |
Answered by
makspll
Feb 13, 2025
Replies: 2 comments
|
Hi, i believe adding the |
0 replies
Answer selected by
timClicks
|
That's useful information - thank you! |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, i believe adding the
ScriptAssetto the asset server is enough, you dont need to manually send the create command, the asset server will trigger aLoadedevent which will in turn trigger the script loading pipeline.