Cannot reference other scripts in @tool script

Godot Version 4.2

Cannot reference other scripts in @tool script.

I have MyObject.gd which extends MyBaseObject.gd and an autoload Utilities.gd, all of which are annotated @tool.

MyObject.gd calls base_functionality() from MyBaseObject.gd and shared_functionality() from Utilities.gd.

When running the game the code is correctly executed (no error messages and it has the desired effect).

When opening the editor, the function calls to base_functionality() and shared_functionality() fail with Invalid call. Nonexistent function ... and the desired effect does not happen.

# MyObject.gd
@tool
extends "res://script/MyBaseObject.gd"

func _ready():
   base_functionality()
   Utilities.shared_functionality()
# MyBaseObject.gd
@tool
extends Node

func base_functionality():
   print("Hello base")
# Utilities.gd
@tool
extends Node

func shared_functionality():
   print("Hello utilities")

base_functionality() should work. shared_functionality() misses the singleton’s definition, should be Utilities.shared_functionality().

@tool
extends "res://tool_test/base.gd"

func _ready() -> void:
	base_functionality()
	Utilities.shared_functionality()

With that singleton change, this all works for me. Could you show the real scripts that are causing issue?

1 Like

It’s because of the updated resource loading. I can see that you’re still opting to use the 3.0 script or trying to migrate your scriptings. it’s covered here; https://docs.godotengine.org/en/stable/tutorials/performance/index.html
You can probably create a list for loaded or preloaded resources. Otherwise it’s just the matter of which resource actually loaded first. Maybe check the Autoload in the Project Settings. I think that’s the new guy!

What do you mean “opting to use the 3.0 script”?

That link is unrelated.

The autoload is loaded when running the game, but not in the editor.

Apparently, @tool only considers the current script and builtins - calling any functions from the current scene also does not work - whether from the parent script of the current node or for any child nodes.

1 Like

That was a typo when creating the minimal example, but I can put these files exactly like that in my project and it fails as described.

I don’t know what you’re talking about. If calling a functionality form script like ;

$Node.easy_func(this_func)
or
add_child(variable_name)
variable_name.easy_func(this_func)
```does not produce any errors. I don't think you know what you're talking about if you think the performance has nothing to do with this question.

I’m very tired. @tool is used for accepting limited debugging functionalities directly in the editor. As if you were running the program. https://docs.godotengine.org/en/stable/tutorials/plugins/running_code_in_the_editor.html
What are you doing @tool?

@tool is used to hot swap access to a Considerable SQL Server and Batched Server Windows. at least in Windows. Again. What are you doing @tool?

Could I see a screenshot? I am testing on 4.2.2 specifically, are you on 4.2.0? Maybe try upgrading