Godot Version
v4.3.stable.official [77dcf97d8]
Question
I have a tool script that looks like:
@tool
extends Node
@export var obj : NamedClass
func _process(delta: float) -> void:
if is_instance_valid(obj):
print(obj.get_value())
and another script that is
extends Node
class_name NamedClass
var value := 1337 : get = get_value
func get_value() -> int:
return value
The scene tree is just theses two nodes, the tool is the root, and the NamedClass is the only child.
In the inspector I can put a reference to the NamedClass node in the tool node.
The is_instance_valid(obj)
recognizes that the reference exists but the obj.get_value()
doesn’t work.
The error says:
res://tool_script.gd:8 - Invalid call. Nonexistent function 'get_value' in base 'Node (NamedClass)'.
which is weird because the editor knows that the function does exists, as it autocomplete when I’m typing, and if I print out the obj.get_method_list()
the method I’m trying to access is there.
The error only shows in the editor, if I run the scene it works as intended.
Also worth noting that I can access the value
if I tag it as @export
, but this completely ignores the getter.
My question then is two-fold:
- Is there a way to access the functions without making the NamedClass also a tool?
- Why does the error says that the function doesn’t exist?