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
C# Exports ignore default values for indirect getters #90872
Comments
This is expected, the source generator can only figure out the default value for simple properties. See the note in the C# exported properties documentation page that was added in godotengine/godot-docs#8859:
So in your MRP the default value for internal static Dictionary<StringName, Variant> GetGodotPropertyDefaultValues()
{
var values = new Dictionary<StringName, Variant>();
int __Baz_default_value = default; // The default value for int is 0.
values.Add(PropertyName.Baz, Variant.From<int>(__Baz_default_value));
int __Qux_default_value = 7;
values.Add(PropertyName.Qux, Variant.From<int>(__Qux_default_value));
return values;
}
Why is that difficult? I'm interested in hearing more about your specific use case. |
I see. Would you say explicitly specifying the default value would solve your problem? If so, you can override the public override bool _PropertyCanRevert(StringName property)
{
if (property == PropertyName.Baz)
{
return true;
}
return base._PropertyCanRevert(property);
}
public override Variant _PropertyGetRevert(StringName property)
{
if (property == PropertyName.Baz)
{
return 8;
}
return base._PropertyGetRevert(property);
} These methods, along with |
Oh that works great! I wasn't familiar with these two. I think they're pretty self explanatory if we were to link to their definition as part of that note in the docs. I'll make a PR tomorrow. Thanks for the great insight! |
Tested versions
Godot v4.3.dev.mono (4728ff3)
System information
Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3060 (NVIDIA; 31.0.15.4601) - AMD Ryzen 9 3900X 12-Core Processor (24 Threads)
Issue description
When an export property has a getter that points to a non-constant value, it defaults to the type's default value. It's understandable why this is difficult to do, but makes tool scripts or plugins difficult to make and use, so this would be a good spot to brainstorm workarounds if a solution can't be proposed.
Steps to reproduce
Open MRP. Note that the inspector shows the reset button for the
Baz
property, but notQux
. When clicking the reset button, it can reset to a possibly invalid value outside the constraints of an export hint.Minimal reproduction project (MRP)
defaulttest.zip
The text was updated successfully, but these errors were encountered: