Repository navigation
|
Hey. I tried to setup the library but I am struggling with attaching the scripts to existing nodes. I can select "RustScript" as a language in Godot and I can find the file in the "Path" field, but I always get the error "rust file is not part of the scripts crate". From what I can tell, I did everything right according to the setup guide, so I am lost here. Could it be because I had to symlink the src directory to // lib.rs
pub mod example_script;
godot_rust_script::define_script_root!();
#[gdextension]
unsafe impl ExtensionLibrary for DropDefense {
fn on_stage_init(stage: InitStage) {
if stage == InitStage::Scene {
godot_rust_script::init!(crate);
}
}
fn on_stage_deinit(stage: InitStage) {
if stage == InitStage::Scene {
godot_rust_script::deinit!();
}
}
}// example_script.rs
#[derive(Debug, GodotScript)]
struct ExampleScript {
#[export]
pub flag: bool,
pub path: GString,
property: Option<Gd<Object>>,
base: Gd<Node3D>,
}
#[godot_script_impl]
impl ExampleScript {
pub fn perform_action(&self, value: i32) -> bool {
value > 0
}
pub fn _process(&mut self, delta: f64) {
godot_print!(
"example script doing process stuff: {}, {}",
delta,
self.base
);
}
} |
Replies: 1 comment 1 reply
|
I reckon that error comes from validate_path in RustScriptLanguage, which rejects any script whose path does not start with the directory the library registered as its script root. The registered root is not the whole crate, it is computed by the define_script_root! macro as CARGO_MANIFEST_DIR, then "/src", then the crate's module path with "::" turned into "/" and the crate name's dashes turned into underscores.
Sorry if I explained it way too clumsy :) Good luck! |
I reckon that error comes from validate_path in RustScriptLanguage, which rejects any script whose path does not start with the directory the library registered as its script root. The registered root is not the whole crate, it is computed by the define_script_root! macro as CARGO_MANIFEST_DIR, then "/src", then the crate's module path with "::" turned into "/" and the crate name's dashes turned into underscores.
So if your crate is named my-game and your init! macro is invoked from the module my_game::scripts, the accepted root is /src/scripts, and a .rs file anywhere else in the crate fails that starts_with check and produces exactly this message. Two conditions therefore have to hold.