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 export variable unit hints to Inspector #10498

Closed
ShawnHardern opened this issue Aug 19, 2024 · 7 comments
Closed

Add export variable unit hints to Inspector #10498

ShawnHardern opened this issue Aug 19, 2024 · 7 comments

Comments

@ShawnHardern
Copy link

Describe the project you are working on

A game prototype that makes heavy use of the inspector in the godot editor.

Describe the problem or limitation you are having in your project

While prototyping a game, I often change various variables such as speeds, angles, pixel values, and other parameters directly in the Inspector to modify and fine-tune my game mechanics.

The Inspector allows me to quickly and easily adjustment these values during development, but a key limitation I encounter is the lack of clarity regarding the units of these variables.

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

I propose extending the existing PropertyHint system in Godot (both in GDScript and C#) to allow for an additional unit hint to be displayed next to exported variables in the Inspector. This unit hint would provide context about the expected units of measurement (e.g., m/s, px, deg) for specific variables, making it easier for developers to understand and adjust their values directly in the Inspector.

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

I propose extending the existing PropertyHint system in Godot (both in GDScript and C#) to allow for an additional unit hint to be displayed next to exported variables in the Inspector. This unit hint would provide context about the expected units of measurement (e.g., m/s, px, deg) for specific variables, making it easier for developers to understand and adjust their values directly in the Inspector.

Possible Gdscript Example

@export_unit("px") var height

Possible C# Example

[Export(PropertyHint.Unit, "px")]
public int height{ get; set; }

Possible Screen Mockup #1
Mockup1
Possible Screen Mockup #2
Mockup2

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

I don't believe there is currently a way to do this

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

It relates to how the core editor currently works

@AThousandShips
Copy link
Member

AThousandShips commented Aug 19, 2024

Why would you need a separate unit displayed beyond the existing unit suffix? What is insufficient about using the existing suffix:px for example

@Castro1709
Copy link

I think maybe you are not aware of it but you can do that with the suffix hint like this:

@export_range(0, 100, 1.0, "suffix:px") var pixel_range : float = 80.0

@AThousandShips
Copy link
Member

Or with @export_custom (not sure if there's a direct equivalent in C#, not familiar with exports there)

@ShawnHardern
Copy link
Author

Hey @Castro1709 and @AThousandShips, 👋🏻

Thanks so much for bringing this to my attention 😄 . I was referring to the information available in GDScript exported properties docs and C# exported properties docs, but I didn’t come across this feature there.

I will investigate this further and will update the documentation to include this information if appropriate.

@ShawnHardern
Copy link
Author

ShawnHardern commented Aug 19, 2024

In case this helps anyone, I wanted to share that this feature indeed already exists! 🥳

Gdscript Example

@export_custom(PROPERTY_HINT_NONE, "suffix:m/s\u00b2") var gravity :float

C# Example

[Export(PropertyHint.None,"suffix:m/s\u00b2")]
private float _gravity = 9.8f;

In Inspector
suffix

@AThousandShips
Copy link
Member

Closing as already implemented, thank you for your proposal nonetheless

@ShawnHardern
Copy link
Author

Closing as already implemented, thank you for your proposal nonetheless

Thanks for your time @AThousandShips, I have created docs PR #9785 to surface this functionality better

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

3 participants