Skip to content

GDScriptNativeClass reported as Object but missing methods in GDScript #77567

Open
@kumikumi

Description

@kumikumi

Godot version

4.0.2

System information

  • OS: Ubuntu 22.04
  • Godot version: 4.0.2

Issue description

The type GDScriptNativeClass is not exposed to GDScript, but a value of such type can be obtained during runtime.

The value seems indistinquishable from a valid Object and appears to have a "get_method_list" function, but trying to call it results in a crash.

I believe the value is Object check in the attached code should either evaluate to false, or the value should have the methods that Objects have according to the docs.

Edit: Turns out that it works if you cast it to Object first (see code example)

Steps to reproduce

func inspect_variant(value: Variant):
	print(value) # <GDScriptNativeClass#-9223372028063514189>
	print("Is object: ", value is Object) # Is object: true
	print("Is valid: ", is_instance_valid(value)) # Is valid: true
	print("Has get_method_list: ", "get_method_list" in value) # Has get_method_list: true
	print(value.get_method_list) # GDScriptNativeClass::get_method_list
	print(value["get_method_list"]) # GDScriptNativeClass::get_method_list
	#print("method list: ", value.get_method_list()) # Invalid call. Nonexistent function 'get_method_list' in base 'Button'
	print("method list: ", (value as Object).get_method_list()) # Works!

func _init():
	var foo = Button
	inspect_variant(foo)

Minimal reproduction project

N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions