Godot Version
4.3
Question
So I’ve run into a ‘problem’ where I am increasingly marking more and more of my scripts as tool scripts. The wiki says to be extremely cautious when doing this - but I find a lot of helpful functionality is locked behind scripts having the tool annotation.
For instance, exposing properties in the inspector only when other properties are set to certain values, like an enum.
In my current project, I have an enum to select what type of firing a weapon does, simultaneous (shooting all projectiles at once in a spread pattern) or burst (shooting them one after the other in a straight line).
For the burst shooting type, I have a variable called burstInterval - the specifics of how that works is unimportant - but it is only relevant if the node has it’s shootType set to Burst. So, in the script I can do this:
func _get_property_list():
var properties = []
if shootType == ShootType.BURST:
properties.append({
"name" : "burstInterval",
"type" : TYPE_FLOAT,
"usage" : PROPERTY_USAGE_DEFAULT
})
return properties
It also lets me clamp the values in the inspector, stopping them from going above or below a certain point that needs calculating depending on other properties. In my example, burstInterval shouldn’t ever be greater than the fire rate (how long between shots in seconds) and the projectile amount.
If I am shooting 3 projectiles every 1 second, at most each projectile can take 0.333 seconds to fire, anything above that would cause problems. Marking the script as a tool script allows me to do this:
var burstInterval : float : set = SetBurstInterval
func SetBurstInterval(value : float):
burstInterval = clampf(value, 0, fireRate / projectileAmt)
Ensuring that when I am setting the value in the inspector, it cannot go above that number, or below 0.
But this script I have marked as a tool script is a class that others extend from - and to use this functionality in those, I also have to mark them as tool scripts. Even if there is no functionality in that script that requires the tool annotation.
I’m just unsure if I am setting myself up for disaster by using stuff like this in so many places, or if I should avoid it and just deal with the inconvenience of having to manage these things manually instead.
Thanks for reading.