Godot-proposals: Warn if script inheriting tool script isn't tool

Created on 26 Apr 2020  路  4Comments  路  Source: godotengine/godot-proposals

Describe the project you are working on:
A complex metroidvania game.

Describe the problem or limitation you are having in your project:
I use tool scripts a lot in my project, because they are handy to update a scene based on exported properties. For a particular example, I have a class (with class_name) called NPC, which has basic interaction code and uses tool for updating sprite based on a variable. However the base NPC is little useful, so each NPC inherits it and provides own interaction code.

My problem is that the inheriting script must be a tool too. I've ran into this multiple times already - when you inherit tool script, the inheriting script must be explicitly tool too or it won't work as such.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
I forgot to enable it few times and it caused some confusion, so I thought that a warning when inheriting script doesn't have tool keyword would be useful. This way instead of wasting few minutes trying to figure out why the script behaves weird, you could just see that you forgot to make it tool.

Alternatively we could make the inheriting script automatically be a tool.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
If a script inherits tool script, warn if it doesn't have tool keyword too. It would be a standard warning, so someone could disable it if their action was intended.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
Inheriting tool scripts might not be a very common operation, but there's no way to work around my problem.

Is there a reason why this should be core and not an add-on in the asset library?:
Impossible to make plugin for this.

editor gdscript

Most helpful comment

Alternatively we could make the inheriting script automatically be a tool.

Vote for this

All 4 comments

Alternatively we could make the inheriting script automatically be a tool.

Vote for this

Another issue with tool scripts is that if they call a function on a singleton that isn't a tool, you get an error message like:
res://Main.gd:8 - Invalid call. Nonexistent function 'foo' in base 'Node (my_singleton.gd)'.

Making the singleton a tool solves the problem, but it's easy to forget to do this, so a warning would be helpful.

Export variable setget functions like this will trigger the error above (if the singleton isn't a tool):

export(int) var my_num := 1 setget set_my_num

func set_my_num(__num: int) -> void:
    my_num = __num
    MySingleton.foo()

Alternatively we could make the inheriting script automatically be a tool.

I'm not fond of making stuff automatically, because it would cause the opposite problem: "Why are my scripts being executed in editor since I didn't mark them as tool?".

Also, it's not clear from the script perspective what is meant to be executed in the editor or not, so it gets tricky to provide more contextual warnings without being annoying.

But it's about the case where base script is tool. It makes sense that inheriting should be tool too. It's not that common and it shouldn't confuse anyone.

Was this page helpful?
0 / 5 - 0 ratings