-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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
@export_tool_button
breaks when changing the script contents (lambda hot-reloading)
#97834
Comments
Makes me wonder: was it really a good idea to serialize a callable here? IMO just marking a function name as a tool button would be enough and simpler |
I tested the issue, it has several parts. 1. Hot reloading only breaks when adding new lambdas. It does not break if you add a new variable (even an exported one) that does not contain a lambda. The class variable initializers are compiled in a single godot/modules/gdscript/gdscript_compiler.cpp Lines 3203 to 3206 in 4c4e673
If you swap two variables, then after saving the script and reselecting the node, the buttons will swap, but will perform actions in the old order. CC @rune-scape 2. Newly added properties are I have an idea about default values, and I noticed a bit of refactoring in that area would be desirable ( 3. Regarding the use of lambda callables, the documentation already warns that it is not advisable for
If you use method callables, you will not have problem 1, only 2 (but this can be fixed by restarting the scene/editor). Alternatively, you can use a getter instead of assigning a lambda to a variable. This is similar to the feature that will be implemented for C# (see #97894), but a bit more verbose since GDScript does not have the @export_tool_button("Hello world")
var hello_world:
get:
return func (): print("Hello world") With this proposal we could reduce the boilerplate: @export_tool_button("Hello world")
var hello_world => func (): print("Hello world") But I'm not sure that's a good enough justification, since the problem is limited to hot reloading and lambda callables; method callables seem pretty robust. Tool scripts may not be comfortable to develop and debug, but once you're done there shouldn't be any problems. |
Sorry, what's the recommended way to use |
i have an idea on how to fix lambda hot swapping is mostly a guessing game for unnamed lambdas, as it too hard to reliably tell where the text has been moved, if it even makes sense to replace, and the new function might not even be compatible hotswapping lambdas is a delicate process, as there are some internal properties (captures and |
@akien-mga this bug makes tool buttons unusable, should we roll back tool buttons in 4.4 if this is 4.5? |
Since reloading the project seems to fix the issue, I think the feature is still worth having, even if hot reloading is broken. Hot reloading for tool scripts has never been very reliable, especially with lambdas. I get that the issue is a bit frustrating but it's something that will mostly be a hassle while developing custom tooling. Once the custom tooling is made, the whole team can use it just fine. |
This is one of the reasons why it is hard for us to fix this, let alone hot reload lambdas. So using member function callable or variable getter is more reliable than lambda. Maybe we should introduce short getter syntax, see #99199. |
@export_tool_button
breaks when changing the script contents (lambda hot-reloading)
The faster workaround for me is to start and quit the game, instead of reloading the project. Could we put this in the documentation? Also, this suggests that there's something in the code path for starting/stopping that reloads the tool script and is faster than reloading the whole project. |
i would like to mention that using the lambda-in-getter syntax:
this avoids the issue completely! even lambda hot-reloading ones. and its not too much more to type, even if it isn't the thing i'd immediately jump to the intuitive one using a lambda as initializer:
has 2 issues:
and i have a PR that solves the latter issue, #98221 |
Workaround which might help some people: I found the same issue when adding the method name to the export_tool_button like this: My workaround, and what I now do whenever I use export_tool_button, is to keep the method name the same, then change what that method in turn calls. Something like this, which works every time:
|
Tested versions
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:
The button appears in the UI. When I click it, the error message appears:
"Soft reload tool script" doesn't help.
After reloading the whole project though, it works as expected:
But add another tool button, and both of them break again:
Now the first one errors with
and the second one errors with
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.
The text was updated successfully, but these errors were encountered: