Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__before_ready() is not called if there's no #[godot_api] trait impl #913

Open
Houtamelo opened this issue Oct 8, 2024 · 0 comments
Open
Labels
bug c: register Register classes, functions and other symbols to GDScript

Comments

@Houtamelo
Copy link
Contributor

Some features we implemented require __before_ready() to work:

  • OnReady initialization
  • Rpcs configuration

Consider the class:

#[derive(GodotClass)]
#[class(init, base = Node)]
struct MyClass;

If it does not have a IClass impl:

#[godot_api]
impl INode for MyClass {}

Then __before_ready() will never be run, which makes the features above fail "silently".


__before_ready() is only called in code generated by the macro expansion of the #[godot_api] trait impl:

impl ::godot::obj::cap::ImplementsGodotVirtual for OwnerDataApi {
	fn __virtual_call(name: &str) -> ::godot::sys::GDExtensionClassCallVirtual {
		use ::godot::obj::UserClass   as _;
		match name {
			"_ready" => {
				use ::godot::sys;
				type Sig = ((),);
				unsafe extern "C" fn virtual_fn(instance_ptr: sys::GDExtensionClassInstancePtr, args_ptr: *const sys::GDExtensionConstTypePtr, ret: sys::GDExtensionTypePtr) {
					let call_ctx = ::godot::meta::CallContext::func("OwnerDataApi", "ready");
					let _success = ::godot::private::handle_ptrcall_panic(&call_ctx, || <Sig as ::godot::meta::PtrcallSignatureTuple>::in_ptrcall(instance_ptr, &call_ctx, args_ptr, ret, |instance_ptr, params| {
						let () = params;
						let storage = unsafe { ::godot::private::as_storage::<OwnerDataApi>(instance_ptr) };
						let mut instance = ::godot::private::Storage::get_mut(storage);
						instance.__before_ready(); // <---------------------------
					}, sys::PtrcallType::Virtual, ));
				}
				Some(virtual_fn)
			}
			_ => None,
		}
	}
}

A temporary fix is to simply add an empty impl if you don't need to override it:

#[godot_api]
impl INode for MyClass {}
@Bromeon Bromeon added bug c: register Register classes, functions and other symbols to GDScript labels Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug c: register Register classes, functions and other symbols to GDScript
Projects
None yet
Development

No branches or pull requests

2 participants