godotengine / godot

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

Nodes in typed dictionaries do not do not show changes in game made by code (4.4 dev 3 / C#) #97850

Open MatthiasBae opened 2 weeks ago

MatthiasBae commented 2 weeks ago

Tested versions

System information

Godot v4.4.dev3.mono - Windows 10.0.22631 - Multi-window, 2 monitors - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4070 Ti (NVIDIA; 32.0.15.6590) - 13th Gen Intel(R) Core(TM) i9-13900KF (32 threads)

Issue description

I have multiple Nodes (in my case Controls) in a typed dictionary. The key is a string and value is the control.

When I want to access the Control Node in the typed dictionary and change its visibility for example, it does not reflect the made changes in game.

It works fine when the node is just a exported property. But all changes (even changing text of labels) are not showen. When debugging the changes seem to be adopted but in the game window nothing has changed.

Example:

I made two tests.

Pressing Right MouseButton makes changes to the exported Label "SameLabel". This is working fine.

Pressing Left MouseButton wants to make changes to the same Label but it is just in a dictionary. But this is not working. The changes will reflect in code but not in game

Pressing RMB

image

Changes are done correctly

image

Pressing LMB

image

Changes are not done in game

image

Steps to reproduce

  1. Export a Godot.Collections.Dictionary and add a Node as value
  2. Get the Node via Code
  3. Change ANYTHING via code from the Node (This should not work)

Minimal reproduction project (MRP)

Issues.zip

juanjp600 commented 2 weeks ago

I was about to write an issue about the same thing!

I've been chipping away at finding out why this happens. If you look in the scene provided in the MRP you'll find that the dictionary is not serialized correctly; instead of node paths, the entire node is written into the dictionary:

Controls = Dictionary[String, Control]({
"Test": Object(Label,"_import_path":NodePath(""),"unique_name_in_owner":false,"process_mode":0,"process_priority":0,"process_physics_priority":0,"process_thread_group":0,"physics_interpolation_mode":2,"auto_translate_mode":0,"editor_description":"","visible":true,"modulate":Color(1, 1, 1, 1),"self_modulate":Color(1, 1, 1, 1),"show_behind_parent":false,"top_level":false,"clip_children":0,"light_mask":1,"visibility_layer":1,"z_index":0,"z_as_relative":true,"y_sort_enabled":false,"texture_filter":0,"texture_repeat":0,"material":null,"use_parent_material":false,"clip_contents":false,"custom_minimum_size":Vector2(0, 0),"layout_direction":0,"layout_mode":3,"anchors_preset":0,"anchor_left":0.0,"anchor_top":0.0,"anchor_right":0.0,"anchor_bottom":0.0,"offset_left":0.0,"offset_top":0.0,"offset_right":40.0,"offset_bottom":23.0,"grow_horizontal":1,"grow_vertical":1,"rotation":0.0,"scale":Vector2(1, 1),"pivot_offset":Vector2(0, 0),"size_flags_horizontal":1,"size_flags_vertical":4,"size_flags_stretch_ratio":1.0,"localize_numeral_system":true,"tooltip_text":"","tooltip_auto_translate_mode":0,"focus_neighbor_left":NodePath(""),"focus_neighbor_top":NodePath(""),"focus_neighbor_right":NodePath(""),"focus_neighbor_bottom":NodePath(""),"focus_next":NodePath(""),"focus_previous":NodePath(""),"focus_mode":0,"mouse_filter":2,"mouse_force_pass_scroll_events":true,"mouse_default_cursor_shape":0,"shortcut_context":null,"theme":null,"theme_type_variation":&"","text":"Heelloooooo World","label_settings":null,"horizontal_alignment":0,"vertical_alignment":0,"autowrap_mode":0,"justification_flags":163,"clip_text":false,"text_overrun_behavior":0,"ellipsis_char":"…","uppercase":false,"tab_stops":PackedFloat32Array(),"lines_skipped":0,"max_lines_visible":-1,"visible_characters":-1,"visible_characters_behavior":0,"visible_ratio":1.0,"text_direction":0,"language":"","structured_text_bidi_override":0,"structured_text_bidi_override_options":[],"script":null)

})

This means that instead of actually referencing the same node, Godot is incorrectly creating a new duplicate node.

MatthiasBae commented 2 weeks ago

This means that instead of actually referencing the same node, Godot is incorrectly creating a new duplicate node.

I hope they fix this for the next dev version as this seems to be pretty critical in my opinion. It was driving me crazy