Skip to content

Document caveat with @export_tool_button and RefCounted-inheriting classes in GDScript exports - #12197

Open
Calinou wants to merge 1 commit into
godotengine:masterfrom
Calinou:gdscript-exports-tool-button-resource
Open

Document caveat with @export_tool_button and RefCounted-inheriting classes in GDScript exports#12197
Calinou wants to merge 1 commit into
godotengine:masterfrom
Calinou:gdscript-exports-tool-button-resource

Conversation

@Calinou

@Calinou Calinou commented Jul 29, 2026

Copy link
Copy Markdown
Member

@Calinou
Calinou requested review from a team as code owners July 29, 2026 15:53
@Calinou Calinou added enhancement topic:gdscript area:manual Issues and PRs related to the Manual/Tutorials section of the documentation labels Jul 29, 2026
Comment on lines +619 to +621
**Bad:**

::

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use code-example-good and code-example-bad, like here:

**Good**:
.. rst-class:: code-example-good
::
for i in range(10):
print("hello")
**Bad**:
.. rst-class:: code-example-bad
::
for i in range(10):
print("hello")
for i in range(10):
print("hello")

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
or :ref:`Callable.unbind() <class_Callable_method_bind>`.
or :ref:`Callable.unbind() <class_Callable_method_bind>`.
Alternatively, you can use a getter:

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 topic:gdscript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants