godotengine / godotengine/godot

`@export_tool_button` breaks when changing the script contents (lambda hot-reloading)

Open
#97,834 19 comments 13 reactions 0 assignees View on GitHub
bug topic:editor topic:gdscript
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

- Reproducible in 4.4dev3, the web editor

### System information

I'm running MacOS, Firefox, web editor

### Issue description

After adding a new `@export_tool_button` to a script, all tool buttons break. Seems to be fixable only by reloading the entire project.

### Steps to reproduce

My script:

```gdscript
@tool
extends Node

@export_tool_button("Hello world")
var hello_world := func():
print("Hello world")
```

The button appears in the UI. When I click it, the error message appears:

```
The value of property "hello_world" is Nil, but Callable was expected.
```

"Soft reload tool script" doesn't help.

After reloading the whole project though, it works as expected:

```
Hello world
```

But add another tool button, and both of them break again:

```gdscript
@tool
extends Node

@export_tool_button("Hello world")
var hello_world := func():
print("Hello world")

@export_tool_button("Hello world2")
var hello_world2 := func():
print("Hello world2")
```

Now the first one errors with

```
Tool button action "" is an invalid callable.
```

and the second one errors with

```
The value of property "hello_world2" is Nil, but Callable was expected.
```

Reloading the whole project again, again, fixes both problems.

### Minimal reproduction project (MRP)

Sorry I couldn't figure out how to attach the web project, and I running out of time right now.
It's basically the default project with just one scene and one script, that I pasted above.
I'm confident this will show up in any project.

Contributor guide

Open the contributing guide

Research direction

Start with the provided @tool script in Godot 4.4dev3 and reproduce the failure in the web editor after adding an @export_tool_button. Investigate the soft-reload path for script contents and lambda callables. Done means existing and newly added tool buttons remain valid and callable without reloading the whole project.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, godot
Domain
game-dev, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.