You can’t make a regular button to respond to the input in the Editor by just making a @tool script.
What you can do is use the @export_tool_button and hook some logic to it.
Just be aware of this issue that is still not fixed. When you set up your logic for the button, you might need to reload the project for this to work properly.
ok ok, but that’s not making the button work in the editor, that’s just having an entry in the inspector act like a button… not quite the same, is it?
I’m assuming this would imply that if I had a couple of buttons and some other ui elements under some ControlABC scene and I wanted such scene to work in the editor, I wouldn’t be able to use this trick, because they wouldn’t appear in the inspector when I select ControlABC, right?
It’s not the same, but it might solve your issue, depending what you want to achieve.
That’s correct. Here I found a bit more explanation of why that happens.
for editorplugins you can override functions that are named likeforward_input, something like that. The Godot editor is basically written like a game, so _input should work, except on sub-viewports like the edited scene. To make it work on such viewports you have to explicitely forward input to them but it will cause issues with other nodes (like buttons).
If you really need to have a clickable button, you might want to check the EditorScript or EditorPlugin.
I’m really curious though what’s your end goal here? Because I’m pretty sure it can be resolved in a much simpler way than a Plugin.
I’m trying to make an in-editor “level editor”.
My main board game is based on square tiles and it would be ideal if the level editor was capable of showing clickable tiles, where you could click and activate/deactivate them… stuff like that.
It’s a bit of a semplification, I’ll need for tiles to be connected to other, which i would hope to implement with drag and drop, tile to tile, which clearly is too ambitious if even a single click doesn’t work
Why can’t you do it with the @export_tool_button though? Seems like a perfect usecase, and simple to implement too.
The only drawback I see is that it will not be in the scene editor, but in the inspector to the side, which is not that much of an inconvenience, is it?
The only alternative I can think of that would propery satisfy your requirements is making your own EditorPlugin, but that is exponentially harder than using the @export_tool_button. Unless you’re making a huge game, it should be more than enough for you.
Let me know if you have any issues that I can help you with.
As I was saying, it’s because I’d like for the editor to work on the viewport, not via the inspector, when clicking or dragging elements around.
I could definitely use export_tool_button or even provide a dropdown with the list of existing tiles you might want to connect, but that’s definitely not the perfect usecase, it’s working around a limitation to me.
I’ll have a look at the EditorPlugin system, thanks for pointing at it!