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

BIND_VIRTUAL_METHOD in GDextensions doesn't create a virtual function in GDscript #82267

Closed
TrickyFatCat opened this issue Sep 24, 2023 · 1 comment · Fixed by #87758
Closed

Comments

@TrickyFatCat
Copy link

TrickyFatCat commented Sep 24, 2023

Godot version

4.1.1

System information

Pop!_OS 22.04

Issue description

Using BIND_VIRTUAL_METHOD script in _bind_methods() doesn't create a virtual function in GDScript.

Steps to reproduce

  1. Create simple GDextension
  2. Build it
  3. Add to the project
//MyClass.h
#ifndef MYCLASS_H
#define MYCLASS_H

#include <godot_cpp/classes/node.hpp>

namespace godot{
class MyClass : public Node{
	GDCLASS(MyClass, Node)

protected:
	static void _bind_methods();

	void foo();

};
}

#endif

//MyClass.cpp
#include "my_class.h"

#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/variant/variant.hpp>

using namespace godot;


void MyClass::_bind_methods(){
	BIND_VIRTUAL_METHOD(MyClass, foo);
}


void MyClass::foo(){

}

After building the extension, you can MyClass in the editor. However, you can't override foo() function as GDscript doesn't see it and it isn't shown in documentation section.

Minimal reproduction project

N/A

@SilicDev
Copy link
Contributor

SilicDev commented Oct 3, 2023

Related issues:
godot/godot-cpp#910
godot/godot-cpp#1072
godot/godot-cpp#1199

godot/godot-cpp#910 mentions a possible work around by using call("_virtual_func") instead but even that isn't ideal when dealing with multiple related classes (and might not even work when overriding it in C++.)

This is especially annoying as documentation is also broken for GDExtension if I'm not mistaken and makes defining extendable classes quite difficult.

Reimplementing the GDVIRTUAL macros is impossible as Object::get_script_instance and the ScriptInstance class aren't exposed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants