godotengine / godotengine/godot
Editor cannot assign custom node to member in C# script when using [Tool] annotation
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
v4.3.stable.mono.official [77dcf97d8]
### System information
Godot v4.3.stable.mono - Windows 10.0.22631 - Vulkan (Forward+) - integrated AMD Radeon(TM) Graphics (Advanced Micro Devices, Inc.; 31.0.12029.10015) - AMD Ryzen 9 5900HX with Radeon Graphics (16 Threads)
### Issue description
When assigning a custom node to an [Export] member in a C# script, a cast error occurs because the item is assigned with the super type instead of the actual custom node type. This issue only occurs when the script is executed in the editor using the [Tool] annotation. When the project runs normally, the types are assigned correctly.
```
/root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/ExceptionUtils.cs:113 - System.InvalidCastException: Unable to cast object of type 'Godot.Node' to type 'CustomNode'.
at class_error.FailureNode.SetGodotClassPropertyValue(godot_string_name& name, godot_variant& value) in C:\Mateus\Godot Engine\Projetos\class_error\Godot.SourceGenerators\Godot.SourceGenerators.ScriptPropertiesGenerator\class_error.FailureNode_ScriptProperties.generated.cs:line 27
at Godot.Bridge.CSharpInstanceBridge.Set(IntPtr godotObjectGCHandle, godot_string_name* name, godot_variant* value) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/CSharpInstanceBridge.cs:line 57
```
### Steps to reproduce
**Steps to reproduce:**
1. Create a custom node in C#.
2. Create a new scene and attach a C# script to a node in the scene.
3. Annotate the C# script with [Tool] and use the [Export] attribute to specify the custom node type for a member.
4. In the editor, try to assign the custom node to the exported member.
**Expected behavior:** The custom node should be correctly assigned to the member of its specific type.
**Actual behavior:** A cast error occurs because the assigned item type is its super type rather than the specific custom node type.
**Note:** This issue only occurs when the script is executed in the editor. When the project runs normally, the node types are assigned correctly.
### Minimal reproduction project (MRP)
[mrp.zip](https://github.com/user-attachments/files/16808411/class_error.zip)
In the "failure_scene.tscn", there is a custom node property that cannot be assigned in the editor.
Contributor guide
Assessment
This issue has not been assessed yet.