godotengine / godotengine/godot-docs

Notes on the "Running code in the editor" page

Open
#10,785 0 comments 1 reaction 0 assignees View on GitHub
area:manual enhancement
Dominant language
reStructuredText
Stars
5.7k
Forks
3.8k
Avg merge
1d 20h
Merged PRs (30d)
25

Description

**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: https://github.com/godotengine/godot/issues/104398#issuecomment-2743119620

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:
```GDScript
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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.