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

Exported typed variables in a tool script have wrong initial value if not initialized #62363

Open
KoBeWi opened this issue Jun 23, 2022 · 2 comments · May be fixed by #92114
Open

Exported typed variables in a tool script have wrong initial value if not initialized #62363

KoBeWi opened this issue Jun 23, 2022 · 2 comments · May be fixed by #92114

Comments

@KoBeWi
Copy link
Member

KoBeWi commented Jun 23, 2022

Godot version

ecf1877

System information

Windows 10 x64

Issue description

@tool
extends Node
@export var test: int

test will have value saved to scene even when it's not changed. It will save 0. The revert arrow appears, but clicking it does nothing.

Steps to reproduce

  1. Create @tool script
  2. Export a typed variable, but don't initialize it
  3. Try to revert it to default in the inspector

Minimal reproduction project

No response

@dalexeev
Copy link
Member

Addition: this bug occurs after restarting the editor (no reset buttons). After saving the scene, the inspector starts working correctly again.

I could not reproduce the bug with saving default values for nodes. Only for resources ([sub_resource]), but seems to be an old bug not related to @tool.

Variant default_value = ClassDB::class_get_default_property_value(res->get_class(), name);
if (default_value.get_type() != Variant::NIL && bool(Variant::evaluate(Variant::OP_EQUAL, value, default_value))) {
continue;
}

@hsandt
Copy link
Contributor

hsandt commented Jan 19, 2024

Just a few pictures to illustrate what happens when adding @tool later, with numerical properties:

# keep commented out for now
#@tool
class_name Arena
extends Node2D

@export var tilemap_cell_size: float = 16.0
@export var tilemap_width: int = 72
@export var tilemap_height: int = 37

Create Arena node, change properties to see revert arrow button appear:

image

Then uncomment @tool at the top of the script. Issue won't appear at once, but after editor reboot, revert buttons disappeared:

image

Oddly enough, in the reverse way, if you temporarily comment out @tool, the reset to default buttons will reappear immediately, and not disappear even if you uncomment @tool until next reboot.

So my current workaround is to comment @tool once during my work session if I need to revert the properties at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
5 participants