Turn a button into a @tool so it can be used within IDE?

Godot Version

v4.2.1.stable.official [b09f793f5]


In a scene, I have a bunch of “fruit” scenes whose values should be randomized in a specific way. This should be done only within IDE, not within the launched project.

So instead of assigning all the values to all “fruit” manually (there are lots of them), I assigned them all to a group and:

  1. made a button
  2. wrote a script with a function that assigns parameters to all members of “fruit” group
  3. attached the script to the button
  4. turned the button into a tool.

However I can’t connect the function to button’s “button_down” signal obviously (because clicking on a button inside the IDE will just select it), so as a quick hack I connected the “hidden” signal to the function that does the assigning of parameters.

So now every time I hide / unhide the button this script is launched. This works perfectly! But it’s a bit hacky and silly having to turn the button’s visibility on/off every time I want to reassign these values. So I’m wondering: is there a way to turn a button into a properly functional button I can click on while in IDE and that I can use to automate some tasks like this one?

Use an @exported boolean variable and do the randomization when clicking on it in the inspector.


extends Node

@export var randomize_fruits:bool:
		if Engine.is_editor_hint():
func _randomize_fruits() -> void:
	# your randomization code

There are other ways but that’s a quick and fast one

That’s less hacky than what I’m already doing, so it’s an improvement. I could probably just make an enum (instead of a bool from the example) that would point to various functions if I ever need to have a few of them in the same button.

I was hoping there’s a way to turn the button into a real button that I can click on as if it were a part of a launched project because it’d be more practical (it’s slightly handier to click within the scene area on something that’s always prominent than in the Inspector).