Skip to content

[.Net] The key for exported Godot.Collections.Dictionary<Node, ...> becomes null in runtime #107974

Open
@Delsin-Yu

Description

@Delsin-Yu

Tested versions

v4.4.stable.mono.official [4c311cb]
v4.4.1.stable.mono.official [49a5bc7]

System information

Godot v4.4.stable.mono - Windows 10 (build 19044) - Multi-window, 4 monitors - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4060 Ti (NVIDIA; 32.0.15.7283) - AMD Ryzen 9 5900X 12-Core Processor (24 threads)

Issue description

Consider the following example and scene setup:

using Godot;

public partial class Main : Node
{
    [Export] private Godot.Collections.Dictionary<Node2D, int> _data;

    public override void _Ready()
    {
        foreach (var pair in _data)
        {
            GD.Print(pair.Key);
            GD.Print(pair.Value);
        }
    }
}
[gd_scene load_steps=2 format=3 uid="uid://dnrcj8m6viwfu"]

[ext_resource type="Script" uid="uid://bidx84qegm2nn" path="res://Main.cs" id="1_ig7tw"]

[node name="Control" type="Node" node_paths=PackedStringArray("_data")]
script = ExtResource("1_ig7tw")
_data = {
NodePath("Node2D"): 0,
NodePath("Node2D2"): 1
}

[node name="Node2D" type="Node2D" parent="."]

[node name="Node2D2" type="Node2D" parent="."]

When running the scene, the output is the following:

null
0
null
1

Where when using GDScript:

extends Node

@export var _data : Dictionary[Node2D, int];

func _ready() -> void:
	for key in _data:
		print(key);
		print(_data[key]);

The output is correct:

Node2D:<Node2D#29813114202>
0
Node2D2:<Node2D#29829891419>
1

This Issue only happens when the key is Node type, NodePath as key functions correctly.

Steps to reproduce

  1. Download and Open the MRP
  2. Build and run the project
  3. Inspect the incorrect output from Main.cs
  4. Swap the script from Main.cs to main.gd
  5. Run the project
  6. Inspect the correct output from main.gd

Minimal reproduction project (MRP)

MrpNodeTypedDictKeyBecomesNull.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions