Godot script does not recognize the keyword: tool

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sneaky_squirrel

I just started learning the Godot engine today. I am also reading documentation and am stumped with the “tool” keyword.

When I add the “tool” keyword at the start of a functioning script file, Godot claims that there is an:

Error at (1,1): Unexpected “Identifier” in class body.

extends TextureRect

# Called when the node enters the scene tree for the first time.
func _ready():
    pass # Replace with function body.

# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#    pass

I cannot find further documentation beyond this page which claims that adding tool at the start of the file should make it run within the editor.

I’ve also seen a couple of youtube videos where the tool keyword works as described in the documentation, yet the stable release of Godot 3.3 I built from forking and cloning from the Godot repository does not like the identifier. I am at my wit’s end.

Thank you for reading.

If it helps, the usage of the tool keyword is mainly in scripts which assist in the development of a project. The keyword tells the editor to run the script in the editor, and that can be used with utility code to make the editor do things.

Ertain | 2021-11-04 08:46

I know that in godot 4 the keyword has been changed to @tool, and it gives aforementioned error if you try using tool. But for 3.3, I don’t have a clue what would be going on…

aXu_AP | 2021-11-04 19:16

I started a new scene, added in a TextureRect, and attached the code that was given. But I haven’t encountered an error (I’m using version 3.3.3, BTW). Is there any other code associated with this script?

Ertain | 2021-11-05 05:14

Thank you. and everyone else.

Turns out I had forked the repository and cloned from the head of the master branch (Which at the time, was Godot 4.x).

I deleted my local repository of godot, and this time directly cloned the 3.x branch. The syntax for tool in Godot 4 had changed, which was the cause of my issue.

Also, an additional note for any future users. If you want to add Editor functionality, work with the EditorModule class, most of the main classed won’t respond in the editor even if you add the tool keyword (e.g. Node, Control, CanvasItem, Node2D).

sneaky_squirrel | 2021-11-06 17:25