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 var with different name instead of variable name #10973

Open
funatsufumiya opened this issue Oct 15, 2024 · 5 comments
Open

@export var with different name instead of variable name #10973

funatsufumiya opened this issue Oct 15, 2024 · 5 comments

Comments

@funatsufumiya
Copy link

funatsufumiya commented Oct 15, 2024

Describe the project you are working on

2D/3D Game

Describe the problem or limitation you are having in your project

Export variable name can be too long, especially in @export_group, short name would be better.

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

Give option to have different export name instead of var name.

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

Something like

@export_name("Short Name")
@export var this_var_has_very_very_long_name

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

Currently probably there's no option to give different name to export var.

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

If it is able to implement this with addons, please teach me the way.

(This proposal is just same as godotengine/godot#4222)

@OffsetMOSFET
Copy link

OffsetMOSFET commented Oct 15, 2024

What you can currently is have proxy parameters.

@export var foo:
  set(new_value):
    _internal_foo = new_value
  get:
    return _internal_foo

Side Note: They're useful for properties that are connected, because if each property sets the other, that can cause an infinite loop of setters.

@saierXP
Copy link

saierXP commented Oct 15, 2024

If it is able to implement this with addons, please teach me the way.

godot-export-name-addons.zip

The current implementation has bugs:
If it has the same name as a built-in property, it will be changed also.

Exclusion may be achieved by determining the types of the two property editors.
Or determine the path where the property editor is located.

Godot_v4 4-dev3_win64_vdHhtSPuk3

# plugin.gd
@tool
extends EditorPlugin

var ip: EditorInspectorPlugin = load("res://addons/exportname/inspectorPlugin.gd").new()

func _enter_tree():
	add_inspector_plugin(ip)

func _exit_tree():
	remove_inspector_plugin(ip)
# inspectorPlugin.gd
@tool
extends EditorInspectorPlugin

var replaces = {}
func _can_handle(object):
    if object is Node:
        return true

func _parse_property(object, type, name, hint_type, hint_string, usage_flags, wide):
    var export_name = hint_string.split("$")
    if export_name.size() > 2:
        replaces[name] = export_name[1]

func _parse_end(object):
    replacePropertyEditor()

func replacePropertyEditor():
    var eps = EditorInterface.get_inspector().find_children("*", "EditorProperty", true, false)
    for ep in eps:
        if replaces.has(ep.get_edited_property()):
            ep.label = replaces[ep.get_edited_property()]

@hiddenBit3000
Copy link

i would suggest maybe an even shorter way like this if its possible:

@export("Use delay (s)") var useDelay: float

this example (adding a unit to my variable name in editor) is where i first was looking if this is possible.

@dalexeev
Copy link
Member

@hiddenBit3000
Copy link

hiddenBit3000 commented Oct 19, 2024

i would suggest maybe an even shorter way like this if its possible:

@export("Use delay (s)") var useDelay: float

this example (adding a unit to my variable name in editor) is where i first was looking if this is possible.

nevermind. i found an existing solution for my topic:

@export_custom(PROPERTY_HINT_NONE, "suffix:sec") var useDelay:float

image

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

5 participants