Skip to content

Notes on the "Running code in the editor" page #10785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
KoBeWi opened this issue Mar 21, 2025 · 0 comments
Open

Notes on the "Running code in the editor" page #10785

KoBeWi opened this issue Mar 21, 2025 · 0 comments
Labels
area:manual Issues and PRs related to the Manual/Tutorials section of the documentation enhancement

Comments

@KoBeWi
Copy link
Member

KoBeWi commented Mar 21, 2025

Your Godot version:

4.5 dev1

Issue description:

I've read "Running code in the editor" and it contains some outdated/false information.

Any other GDScript that your tool script uses must also be a tool. Any GDScript without @tool used by the editor will act like an empty file!

The first part is misinformed. See my explanation here: godotengine/godot#104398 (comment)

The second part is outright wrong. You can access constants of non-tool scripts, so they are not completely "empty".

Extending a @tool script does not automatically make the extending script a @tool. Omitting @tool from the extending script will disable tool behavior from the super class.

That one is correct, but we have a new warning for that, so it might be worth mentioning.

Modifications in the editor are permanent.

You can utilize editor's undo/redo to make them non-permanent. Although here it could be only briefly mentioned, something like ", unless you use editor's undo/redo system.". It can be clarified more in the EditorScript section below.

You may need to restart the editor. This is a known bug found in all Godot 4 versions

Restarting the editor is (almost?) never needed. In most cases it's enough to reload the scene. While a tool scrip will work immediately (unless it's built-in), scene reload will re-initialize it's state properly if it was just changed to tool.

In case of _process() a scene reload is needed, because processing is enabled in node's NOTIFICATION_READY, which is normally received only once per node. If you make script into tool, or attach a script to existing node, you will need to reload scene to enable or disable processing.

Autoload nodes cannot be accessed in the editor at all.

Autoloads are normally accessible, otherwise the scripts wouldn't compile. But again, if the autoload is non-tool (which means it exists in the editor without script instance), you can only access constants.

changed.emit()

There is emit_changed() method for that (which does the same, but it's preferred over manually emitting).

EditorScripts have no undo/redo functionality, so make sure to save your scene before running one if the script is designed to modify any data.

There is EditorInterface.get_editor_undo_redo() now.


For potential additions:

  • The new @tool_button annotation could be mentioned.
  • A neat trick to avoid some editor_hint() checks is doing:
func _ready():
	if Engine.is_editor_hint():
		set_process(false)

This is useful if your node does not need to be processed in the editor.

  • Any @tool script has access to editor classes, and especially EditorInterface, which allows things like aforementioned undo/redo. However directly referencing any editor class will make the script not work at runtime.

URL to the documentation page (if already existing):

https://docs.godotengine.org/en/latest/tutorials/plugins/running_code_in_the_editor.html

@KoBeWi KoBeWi added area:manual Issues and PRs related to the Manual/Tutorials section of the documentation enhancement labels Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:manual Issues and PRs related to the Manual/Tutorials section of the documentation enhancement
Projects
None yet
Development

No branches or pull requests

1 participant