Another tool
improvement porposition, but without opt in/out of functions
#7388
Replies: 3 comments 3 replies
-
I think this would work. The idea had crossed my mind before, but I didn't attempt to write a proposal for it, see #6767 (comment) I didn't think of Something else: I believe there is value in By the way, since this is a breaking change, I' guessing it would be for Godot 5. |
Beta Was this translation helpful? Give feedback.
-
I agree that some solution is needed, using editor hint at the beginning of every function adds noise and potentially some overhead if the code is hot.
This solution would also be non-breaking change. |
Beta Was this translation helpful? Give feedback.
-
See also #729 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Yes, tooling is great
...but it's also quite finicky. Sometimes have to implement a lot of safeguards just for simple usage. And there have been some suggestions on how to improve it, but most are based on adding annotations on functions to opt in/out of executing them in the editor.
My suggestion is to make
tool
run the same stuff it already does inside the editor, EXCEPT the node's_process
and_physics_process
functions. And for the cases where processing is needed, add two new built-in functions,_tool_process
and_tool_physics_process
.Care to explain?
Alright, let's do this in parts. Disclaimer that my GDScript sintax will be of godot 3, since it's the one I use the most.
First one is to make
tool
not run both_process
and_physics_process
. The use case for this would be for simple things: a setter function that changes/adjusts the way the node is displayed according to an exported variable; a simple drawing that occurs inside the_ready
function that shows a launchpad trajectory.If you need to separate some code to run only in game or in editor inside a setter or ready function, then you'd use the
Engine.editor_hint
we already have.But what if you need the process function to run inside the editor?
That's where the new built-ins
_tool_process
and_tool_physics_process
comes in! The idea is that the editor would run these two functions, instead of the_process
and_physics_process
.When you would need to run a script in editor and another in game, simply put the code in the appropriate function.
For the cases where you need to run a process function insinde both the game and the editor, you can simply call it inside the correspoding tool function.
If you need to add new behaviour in the middle of the code that run in the process function... yeah well in this case all I can think of is to copy/paste your process function logic inside the tool function, and change what you'd like.
In this specific scenario code duplication would be needed, and if you modify the game logic you'd have to modify the tool logic to match it. But it can be migitaged depending on how you structure your code. If all your game logics are inside helper functions, and there are only function calls inside the process function, for instance.
What do you guys think?
I think this proposition makes tooling use to follow the complexity of the code you need to run in the editor. Simple cases would need simple adjustments, and more complex ones would require a bit more thinking, depending on your needs. And also don't know how to adjust the proposed system to avoid code duplication in more complex editor processing scenarios, but I'm think those would not be the majority of tooling uses.
Beta Was this translation helpful? Give feedback.
All reactions