Access the property of an instantiated scene in a plugin

Godot Version



I’m trying to make a plugin that displays a context menu on click but I’m stuck here, calling a method from an instantiated scene.


extends EditorPlugin
var dock:Context

func _init() -> void:

func _enter_tree() -> void:
	# Initialization of the plugin goes here.	
	dock  = preload("res://addons/context_menu/context.tscn").instantiate()

func _exit_tree() -> void:
func screen_changed(screen)->void:
	if dock:
		if dock.has_method("setCurrentScreen"):

[ - attached to context.tscn]

extends Control
class_name Context
var currentScreen:String

func _input(event: InputEvent) -> void:
	if event is InputEventMouseButton: 
		if event.button_index == MOUSE_BUTTON_LEFT: 
			if event.pressed:
				if currentScreen != "3D": return
				$cm.position = get_viewport().get_mouse_position()

func setCurrentScreen(val:String)->void:
	currentScreen = val

res://addons/context_menu/ - Invalid call. Nonexistent function ‘setCurrentScreen’ in base ‘Control (Context)’.

how is it possible that “has_method” evaluates to true and at the same time sends me the error that the function does not exist?

I had to use the @tool keyword also in my instantiated scene script. That’s why it wasn’t working :expressionless:

extends Control
class_name Context