Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export method as button in inspector #9380

Closed
TeddyDD opened this issue Jun 25, 2017 · 21 comments
Closed

Export method as button in inspector #9380

TeddyDD opened this issue Jun 25, 2017 · 21 comments

Comments

@TeddyDD
Copy link

TeddyDD commented Jun 25, 2017

Operating system or device - Godot version:
3.x I guess

Idea
Just an idea but I think it's worth discussing.
I think it might be useful to export method in from a node so it would show up as a button in the inspector. Clicking the button would run exported method. Script using such feature would have to use tool keyword of course.

I saw @kubecz3k have been using setgets in his Finite State Machine plugin for similar behavior - you can write state name into exported string and then setget handles creation of the state (or something like that, I haven't read the code yet). I think my idea is cleaner approach for tools working in editor.

Example

tool
extends Node2D
export var something = "foo"
export my_func "Create Foo" # function name, button text

func my_func(): # no parameters!
    # do something
    # no return, runs purely for side effects

insp-bttn-mckp

Downsides
I'm not sure if inspector is good place to that kind of functionality. On the other hand writing editor plugin that adds few buttons to toolbar seems to be overkill to me. As an alternative to my idea I'd suggest putting exported functions/buttons in the toolbar when the node is selected - editor would handle adding/removing button automatically.
mkp2

What do you think?

@reduz
Copy link
Member

reduz commented Jun 25, 2017 via email

@Zylann
Copy link
Contributor

Zylann commented Jun 26, 2017

How would actions like this fit with undo/redo?
That sounds handy for "quick'n dirty" tooling, but on the long run I would use EditorPlugin for this tbh.

@reduz
Copy link
Member

reduz commented Jun 26, 2017 via email

@willnationsdev
Copy link
Contributor

Perhaps something more like a parameter for the export function that just causes the bool's representation in the inspector to become a ToolButton rather than a CheckButton?

export(bool, TOOL_BUTTON) var create_foo setget on_create_foo_button_pressed

func on_create_foo_button_pressed():
    # do stuff

@reduz
Copy link
Member

reduz commented Oct 25, 2017 via email

@maikramer
Copy link

I'm really waiting for something like this one, I want to create a generate map button, like I have in my unity version, in unity, we can override some inspector methods, like draw and OnInspectorGUI (when something change in inspector), maybe we could have a way to override inspector and include buttons, fields, and things like we can in unity.

@ghost
Copy link

ghost commented Apr 13, 2019

What's the status of this issue? As @maikramer mentioned, such feature is useful in regenerating the map inside editor. It's doable as editor plugin but it's needed as node's properties

@willnationsdev
Copy link
Contributor

@ShrewdSpirit There isn't a built-in way to do this without using an EditorInspectorPlugin from one's own EditorPlugin, for now. In my godot-next repository, I've created an EditorInspectorPlugin that delegates the task of creating the Inspector GUI additions to the object being edited in the Inspector, so you can now just add methods to a script to make stuff show up in that class's Inspector. We also have utilities to assist with this for buttons via our InspectorControls class. For example...

extends Node
func _parse_begin(p_inspector_plugin):
    p_inspector_plugin.add_custom_control(InspectorControls.new_button("Generate Map", false, self, "_on_generate_map")
func _on_generate_map():
    pass # generate the map

If people like the idea, I can discuss the idea of porting our DelegationInspectorPlugin (which enables this functionality) to the Godot Editor. I just haven't considered porting it cause I figured reduz had a reason not to include the functionality this way in the first place.

@ghost
Copy link

ghost commented Apr 13, 2019

@willnationsdev The idea of what you've done is interesting. I'll try your method

@thorlucas
Copy link

Any update on this? Unity's editor tools are very powerful. Not having this in Godot is rather disappointing

@Calinou
Copy link
Member

Calinou commented Apr 28, 2020

@thorlucas It seems nobody has started working on this feature yet. As a workaround, you can use a boolean exported property that has a setget method that will run a method when set to true (without actually changing the property's value).

@willnationsdev
Copy link
Contributor

I bet you could probably write an EditorInspectorPlugin that could do something like this. Have it get the edited object, iterate through its list of methods, and then, based on a name convention (since annotations aren't supported yet), generate GUI elements in the Inspector such as a button, and then program that button to execute the method if pressed. So, it would be more about having magic methods that generate it (for now).

@Zylann
Copy link
Contributor

Zylann commented Apr 28, 2020

Annotation sounds better for a short form 🧙

@inspector_button
func say_hello():
    print("Hello! Follow me")

As a shortcut for [Insert all the EditorInspectorPlugin stuff to do in order to have a button in the inspector to call a script method]

@thorlucas

This comment has been minimized.

@Calinou
Copy link
Member

Calinou commented Apr 28, 2020

@thorlucas Please don't bump issues without contributing significant new information. Use the 👍 reaction button on the first post instead.

@akien-mga
Copy link
Member

Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine.

The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker.

If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance!

@cgbeutler
Copy link

cgbeutler commented Jan 19, 2021

Google took me to this issue. Did this have a new proposal opened that can be linked to?
The latest docs don't mention this feature, but if it will already be in 4.0, that would also be good to know.

@Calinou
Copy link
Member

Calinou commented Jan 19, 2021

Google took me to this issue. Did this have a new proposal opened that can be linked to?

Not yet, but I can open one.

The latest docs don't mention this feature, but if it will already be in 4.0, that would also be good to know.

There's already a hack you can use using a boolean exported property: godotengine/godot-docs#4106

Given it's a hack, the PR above will probably not be merged.

@akien-mga
Copy link
Member

Yeah I'd prefer that we implement a proper way to export a toggle button that would be linked to a method, as it's a very useful feature and it would be worth serving properly with a supported method.

@barrrettt
Copy link

umm no yet?? At the moment I use the hack( c#):
[Export] public bool update {set { updateMeshData(); } get{return true;}}

@dylan-grafmyre
Copy link

Similar to Barrrettt;s post, I think this is a close gdscript equivalent

tool
extends Spatial

export(bool) var update setget _update

func _update(value):
	print(self, ' ', '_update')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests