0 votes

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.

tool
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.
https://docs.godotengine.org/en/stable/tutorials/misc/running_code_in_the_editor.html#doc-running-code-in-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.

Godot version 3.3
in Engine by (12 points)

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.

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...

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?

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).

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.