Document caveat with @export_tool_button and RefCounted-inheriting classes in GDScript exports - #12197
Open
Calinou wants to merge 1 commit into
Open
Conversation
Calinou
commented
Jul 29, 2026
Member
- See export_tool_button self-referencing resources godot-proposals#15276.
…classes in GDScript exports
dalexeev
reviewed
Jul 29, 2026
Comment on lines
+619
to
+621
| **Bad:** | ||
|
|
||
| :: |
Contributor
There was a problem hiding this comment.
You can use code-example-good and code-example-bad, like here:
godot-docs/tutorials/scripting/gdscript/gdscript_styleguide.rst
Lines 124 to 143 in 98cd4a4
dalexeev
reviewed
Jul 29, 2026
Comment on lines
+626
to
+638
| @export_tool_button("My Button", "Callable") var mybutton = func(): | ||
| self.some_var = some_func() | ||
|
|
||
| **Good:** | ||
|
|
||
| :: | ||
|
|
||
| @tool | ||
| extends Resource | ||
|
|
||
| @export_tool_button("My Button", "Callable") var my_button: | ||
| get: return func(): | ||
| self.some_var = some_func() |
Contributor
There was a problem hiding this comment.
Suggested change
| @export_tool_button("My Button", "Callable") var mybutton = func(): | |
| self.some_var = some_func() | |
| **Good:** | |
| :: | |
| @tool | |
| extends Resource | |
| @export_tool_button("My Button", "Callable") var my_button: | |
| get: return func(): | |
| self.some_var = some_func() | |
| @export_tool_button("My Button") var my_button = func (): | |
| some_var = some_func() | |
| **Good:** | |
| :: | |
| @tool | |
| extends Resource | |
| @export_tool_button("My Button") var my_button: | |
| get: return func (): | |
| some_var = some_func() |
| Avoid storing lambda callables in member variables of RefCounted-based | ||
| classes (e.g. resources), as this can lead to memory leaks. Use only method | ||
| callables and optionally :ref:`Callable.bind() <class_Callable_method_bind>` | ||
| or :ref:`Callable.unbind() <class_Callable_method_bind>`. |
Contributor
There was a problem hiding this comment.
Suggested change
| or :ref:`Callable.unbind() <class_Callable_method_bind>`. | |
| or :ref:`Callable.unbind() <class_Callable_method_bind>`. | |
| Alternatively, you can use a getter: |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.