-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Clarify rules around which scripts require @tool
in Running code in the editor
#10888
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
Calinou
wants to merge
1
commit into
godotengine:master
Choose a base branch
from
Calinou:running-code-in-the-editor-static-context
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -105,20 +105,33 @@ Here is how a ``_process()`` function might look for you: | |||||
// Code to execute both in editor and in game. | ||||||
} | ||||||
|
||||||
.. _doc_running_code_in_the_editor_important_information: | ||||||
|
||||||
Important 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 general rule is that **any other GDScript that your tool script uses must | ||||||
*also* be a tool**. The editor is not able to construct instances from GDScript | ||||||
files without ``@tool``, which means you cannot call methods or reference member | ||||||
variables from them otherwise. However, since static methods, constants and | ||||||
enums can be used without creating an instance, it is possible to call them or | ||||||
reference them from a ``@tool`` script onto other non-tool scripts. One exception to | ||||||
this are :ref:`static variables <doc_gdscript_basics_static_variables>`. | ||||||
If you try to read a static variable's value in a script that does not have | ||||||
``@tool``, it will always return ``null`` but won't print a warning or error | ||||||
when doing so. This restriction does not apply to static methods, which can be | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that static functions can access static variables. Although this is stated above, this exception can be a bit confusing. Is there any way we can clarify this without making the documentation even more complicated? Maybe like this:
Suggested change
|
||||||
called regardless of whether the target script is in tool mode. | ||||||
|
||||||
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. Therefore the extending script should also | ||||||
behavior from the super class. Therefore, the extending script should also | ||||||
specify the ``@tool`` annotation. | ||||||
|
||||||
Modifications in the editor are permanent. For example, in the next | ||||||
section when we remove the script, the node will keep its rotation. Be careful | ||||||
to avoid making unwanted modifications. | ||||||
Modifications in the editor are permanent, with no undo/redo possible. For | ||||||
example, in the next section when we remove the script, the node will keep its | ||||||
rotation. Be careful to avoid making unwanted modifications. Consider setting up | ||||||
:ref:`version control <doc_version_control_systems>` to avoid losing work in | ||||||
case you make a mistake. | ||||||
|
||||||
Try ``@tool`` out | ||||||
----------------- | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
onto
instead ofon
here what is commonly used in the docs?