godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.71k stars 20.12k forks source link

Can't clear exported node in a @tool script. #94396

Open Okxa opened 1 month ago

Okxa commented 1 month ago

Tested versions

v4.2.2.stable.arch_linux

System information

Godot v4.2.2.stable unknown - Arch Linux #1 SMP PREEMPT_DYNAMIC Sun, 16 Jun 2024 19:06:37 +0000 - X11 - Vulkan (Forward+) - dedicated AMD Radeon RX 5700 XT (RADV NAVI10) () - AMD Ryzen 9 5950X 16-Core Processor (32 Threads)

Issue description

Clearing an exported Node using the drop down menu does not clear the property, when in a script which runs in editor using @tool

@export var annotation_node:Node = null

image

Additionally, if exporting a property of type Node with _get_property_list(), results in error when pressing the clear button:

Trying to assign value of type 'NodePath' to a variable of type 'Node'.

Because of the error I believe the issue is probably similiar as in: https://github.com/godotengine/godot/issues/62481. (As the issue says, currently the reset arrow works and set the variable to Nil correctly.)

In fact when printing the type of the value in _set, it gives Object when setting a node, Nil when resetting with the arrow, and NodePath when pressing clear button in the drop down.

For Node exported with @export, when pressing the clear button will not print anything in it's setter, as if the setter is not called:

@export var annotation_node:Node:
    set(value):
        print(type_string(typeof(value)))
        annotation_node = value

Steps to reproduce

  1. Create a script which runs in editor with @tool
  2. Export a property of type Node with @export var node:Node or using get_property_list().
  3. Assign a node to it.
  4. Press the Clear button in the drop down menu.
  5. Observe as the value is not cleared

Minimal reproduction project (MRP)

mrp-node-export-clear.zip

KoBeWi commented 1 month ago

Does it work in 4.3?

Okxa commented 1 month ago

Same behaviour on v4.3.beta3.official [82cedc83c]

KoBeWi commented 1 month ago

If you remove @tool, the node can be cleared normally.