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

Fix tools GDScript export default value type not matching actual type #67618

Closed
wants to merge 1 commit into from

Conversation

idomo1
Copy link

@idomo1 idomo1 commented Oct 19, 2022

Partially fixes #66791 (only partially since there seems to be multiple issues)

This fixes the default value for a tools export being stored as the wrong type when the type annotation doesn't match the primitive type. E.g:

export var test: int = 3.5 // Float being set for int type
export var test2: float = 3 // Int being set for float type
export var test3: bool = 2 // Int being set for bool type

I checked out the 3.5 branch to see how it was handling this, which is by converting the default value before storing it:

/* 3.5 branch */

Variant::Type default_value_type = c->variables[i].default_value.get_type();
Variant::Type export_type = c->variables[i]._export.type;

// Convert the default value to the export type to avoid issues with the property editor and scene serialization.
// This is done only in the export side, the script itself will use the default value with no type change.
if (default_value_type != Variant::NIL && default_value_type != export_type) {
	Variant::CallError ce;
	const Variant *args = &c->variables[i].default_value;
	member_default_values_cache[c->variables[i].identifier] = Variant::construct(export_type, &args, 1, ce);
} else {
	member_default_values_cache[c->variables[i].identifier] = c->variables[i].default_value;
}

And so I just ported that over.

Testing notes

See #66791 for a reproduction project. The variations to test are int, float and bool (Are there any others?).
You'll also need to test around some of the other issues with tools scripts (mentioned in #66791). Reloading the scene a couple times should be enough

@idomo1
Copy link
Author

idomo1 commented Dec 18, 2022

Fixed by #69416

@idomo1 idomo1 closed this Dec 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reverting exported values broken on tool scripts
2 participants