Skip to content

Feature : Handle the hint and hint string for the BindProperty attribute#37

Open
spimort wants to merge 2 commits into
godotengine:masterfrom
spimort:feature/handle-bind-property-hint
Open

Feature : Handle the hint and hint string for the BindProperty attribute#37
spimort wants to merge 2 commits into
godotengine:masterfrom
spimort:feature/handle-bind-property-hint

Conversation

@spimort
Copy link
Copy Markdown

@spimort spimort commented Jul 22, 2025

This feature adds the option to specify the Hint and HintString on the BindPropertyAttribute.
This is useful to handle Godot special property bindings like Files, Directory, Layers3DPhysics, etc.

As of now it seems like it was possible to do it using a "Hand made" BindMethods using the ClassRegistrationContext.
I did not see a way to do it right now with source generator using the attribute, unless I missed something and there is other ways to do it.

This code was inspired by the NameOverride from the CollectCore function.

Unit tests has been done to ensure the result of the code generation.

I hope this can be useful 🙂

@GeorgeS2019
Copy link
Copy Markdown

@spimort
Do you plan to have more interesting examples how to use this Godot dotnet ? I have not found any feedback how easy to use this framework

@spimort
Copy link
Copy Markdown
Author

spimort commented Jul 23, 2025

@GeorgeS2019
I can provide an example project on how to use this feature I added, that should help!

BindPropertyHintExample.zip

Just run the ./publish.sh command (on windows, you can adapt it if you are on linux/mac).
A demo godot project is available under the demo folder (the publish command will already build the addon to the right folder, for the demo).
You can take Default Godot, no C# is required.

This example adds a new node called MyCustomNode.
I've added 3 properties with Hint :

[GodotClass]
public partial class MyCustomNode : Node
{
    [BindProperty(Hint = PropertyHint.Dir)]
    public string DataPath { get; set; }

    [BindProperty(Hint = PropertyHint.Range, HintString = "0,100")]
    public int IntValueWithMinMax { get; set; }

    [BindProperty(Hint = PropertyHint.Link)]
    public Vector3 Vec3WithLinkedValues { get; set; }
}

These properties are then available in the editor :
image

I hope this helps!

@GeorgeS2019
Copy link
Copy Markdown

GeorgeS2019 commented Jul 23, 2025

@spimort
migeran/libgodot#1 (comment)

Thx..Now I know the build is possible

Take a look the above link if you are interested how to combine Godot-Dotnet and LibGodot

A working outdated 2024 version
migeran/libgodot#1 (comment)

@Delsin-Yu
Copy link
Copy Markdown
Contributor

This definitely helped a lot, but personally, I wish the property hint & string usage could be a little bit more typed.

So you do [BindDirectoryProperty], [BindRangeProperty(0, 100)], and [BindLinkProperty] as opposed to writing a random magical number that may crash the editor.

I'm fully aware that the GodotEngine internally uses these magical numbers, but from an API design perspective, I think it's better not to let the user do this all the time. See how GDScript has done this. And we can leave the [BindPropertyCustom(Hint, HintString)] to the advanced users as a last resort.

@spimort
Copy link
Copy Markdown
Author

spimort commented Jul 24, 2025

@Delsin-Yu That's a good idea, I think it would improve the quality of life of the api!

I can make the changes, but I just want to make sure that maintainers are on board with this change to ensure I'm aligning with the project's direction.
Or maybe this is a first iteration? I’m not sure 🙂

@GeorgeS2019
Copy link
Copy Markdown

GeorgeS2019 commented Jul 30, 2025

@spimort

Could you share the steps how you build the project to get the following nugets:

image

I try following the readme.md, full of errors

@spimort
Copy link
Copy Markdown
Author

spimort commented Jul 31, 2025

@GeorgeS2019 make sure to include the flag --warnAsError=false when building 🙂

Then, you can use the flag --pack to generate the packages.

@GeorgeS2019
Copy link
Copy Markdown

GeorgeS2019 commented Jul 31, 2025

# Build all projects.=====> ~ 170 errors
build.cmd --build --warnAsError=false

# Build 'Godot.Bindings' project.
./build.sh --build --projects ./src/Godot.Bindings/Godot.Bindings.csproj

To produce the NuGet packages use the --pack argument.

# Builds all projects and produces NuGet packages for all the packable projects.
./build.sh --build --pack --warnAsError=false

I also just restore Godot.sln and build ..

src/Godot.Bindings/Godot.Bindings.csproj. Fail to build


###However

I am able to fork and use GitHub action based on latest CI instead of nightly workflow to generate the GodotBindingGenerator.exe.

Do you need/use this step??

GodotBindingsGenerator --extension-api [PATH_TO_EXTENSION_API_JSON] --extension-interface [PATH_TO_GDEXTENSION_INTERFACE_HEADER] [PATH_TO_OUTPUT_DIRECTORY]

I presume you use something like this

./build.sh --productBuild --ci /p:VersionPrefix=4.5.0-dev /p:OfficialBuildId=20240319.1 /p:FinalVersionKind=release

@GeorgeS2019
Copy link
Copy Markdown

@spimort

I can provide an example project on how to use this feature I added, that should help!

BindPropertyHintExample.zip

Just run the ./publish.sh command

Thanks .I am able to run in Windows

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants