-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Callables of static methods are not valid if accessed via the class's name #79521
Comments
class_name Test extends Node
static func static_func() -> String:
return "static_func()"
func test_callable(c: Callable) -> void:
print("object=%-32s is_standard=%-5s is_valid=%-5s result=%s" % [
c.get_object(), c.is_standard(), c.is_valid(), c.call()])
func _ready() -> void:
test_callable(Test.static_func)
test_callable(Test.new().static_func)
test_callable(static_func)
In the case of a static method call on a class, the base object is the script. The problem is here: godot/core/variant/callable.cpp Lines 124 to 130 in a758388
Lines 631 to 643 in a758388
These methods cannot be overridden: Lines 817 to 818 in a758388
I'm not sure if we should add the ability to override/customize the methods. We don't have EDIT. I changed my mind. Having static methods in the script's method list would be useful and consistent with static variables (that are in the script's property list). |
Godot version
v4.1.stable.official [9704596], v4.1.1.rc1.official [e709ad4]
System information
Ubuntu 23.04
Issue description
4.1 introduced support for using static methods as callables. However, if the callable is accessed via the class's name, it is considered invalid. This makes using static methods from other classes as callables very difficult.
Steps to reproduce
Minimal reproduction project
ClassNameCallables.zip
The text was updated successfully, but these errors were encountered: