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

Add support for exposing/exporting Script Methods to the Editor #4743

Closed
Diddykonga opened this issue Jun 24, 2022 · 4 comments
Closed

Add support for exposing/exporting Script Methods to the Editor #4743

Diddykonga opened this issue Jun 24, 2022 · 4 comments

Comments

@Diddykonga
Copy link

Diddykonga commented Jun 24, 2022

Describe the project you are working on

N/A

Describe the problem or limitation you are having in your project

Ease of Use and Reusability.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add an Annotation, the name of which can be discussed, that will allow developers to expose/export their Script's Methods to the Editor, allowing them to be run in the Editor. Also expose the UndoRedo Class to GDScript to allow it to be used/passed to Script Methods that are called by the Editor.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Base Example:

var x  : int = 0

@editor
func my_method(): #Doesnt support UndoRedo
    x+=1

One of the drawbacks of the current hack of exposing a Script's Method to the Editor, is that UndoRedo is not supported, which messes with consistency.

To support UndoRedo, any Method called by the Editor with the Annotation will have UndoRedo passed as the first parameter of the Method.

var x  : int = 0

@editor
func my_method(ur : UndoRedo):
    if (ur): #Checking for validity/null, can allow the Method to be called at runtime where you may not care about UndoRedo
        ur.save_state(x) #I dont know what the API of UndoRedo is like, but as an example
    x+=1

Or, maybe some kind of static/global access to the UndoRedo, instead of passing it as an argument.

var x  : int = 0

@editor
func my_method():
    if (UndoRedo::get()):
        UndoRedo::get().save_state(x) #I dont know what the API of UndoRedo is like, but as an example
    x+=1

User-Parameters may be able to be supported by opening a new Popup that shows an inspector of the Parameters allowing you to fill them in, and a button for calling the Method and one for canceling.

If this enhancement will not be used often, can it be worked around with a few lines of script?

An Editor Plugin can be created, although not ideal.

Is there a reason why this should be core and not an add-on in the asset library?

It requires changing alot of core and editor code.

@Diddykonga Diddykonga changed the title Add an Annotation to expose Script Methods to the Editor Add support for exposing/exporting Script Methods to the Editor Jun 24, 2022
@Calinou
Copy link
Member

Calinou commented Jun 25, 2022

Related to #2149. The linked proposal already has an implementation, so I recommend you give it a try locally.

@YuriSizov
Copy link
Contributor

Ease of Use and Reusability.

Can you be more specific what problem does this solve? If it's about the boolean setter trick to expose custom actions to the inspector, then this is a duplicate of the aforementioned proposal. And in that case, we already have a PR that has been discussed and approved with some pending changes.

@Diddykonga
Copy link
Author

Apologies, I should have checked. Closing now.

@KoBeWi
Copy link
Member

KoBeWi commented Jun 26, 2022

Ah I didn't notice this proposal before. It was opened after our discussion on the chat about METHOD_FLAG_EDTIOR.

The problem with #2149's implementation is that it won't support editor's UndoRedo. The UndoRedo is basically only available from plugins and passing it as an argument to the method might be the only option to resolve this. However it will be impossible when godotengine/godot#59564 gets merged.

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

4 participants