godotengine / godot

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

inst_to_dict() and dict_to_inst() doesn't work correct when used with JSON #87832

Open CX97x opened 9 months ago

CX97x commented 9 months ago

Tested versions

4.2.1.stable and 4.2.2.rc

System information

Windows 11

Issue description

  1. inst_to_dict() can't handle types like Color when the dictionary is converted to a String with JSON later, it handles them as String (e. g. "(1, 1, 0, 1)")
  2. dict_to_inst() can assingn other types to a typed variable (e. g. the String from above to var example :Color)
  3. dict_to_inst() can't handle integers and arrays with integers correctly which leads sometimes to problems when comparing two numbers (e. g. a == b returns false if a and b are both 1), because they are parsed as floats later
  4. the editor crashes when using inst_to_dict() in plugins under some circumstances

Steps to reproduce

reproduce 1., 2. and 3: Convert an instance to a dictionary, than to a JSON string and then back to a dictionary and an instance reproduce 4.: try inst_to_dict() on the object of a EditorInspectorPlugin

Minimal reproduction project (MRP)

inst_to_dict() MRP.zip

1., 2. and 3..: run the scene WrongTypes.tscn 3.: I wasn't able to reproduce the comparison error 4.: Open the Resource ClickButtonToCrashTheEditor.tscn and click the crash button

AshutoshAkkole commented 9 months ago

anyone working on this issue? If not I want to

HunterNN commented 6 months ago

Getting the same problem with integers using inst_to_dict(). They appear much bigger then visually displayed. Parsing them to int() creates a big number: int(3) -> 4618441417868443648 Comparing them to other numbers can lead to wrong results: 3 < 99 -> false

OffsetMOSFET commented 1 month ago

With dict_to_inst, I got an issue similar to (2) where I changed the type in my script but loaded an older JSON. Instead of casting it to the type or warning me of the incompatible type, it stored the outdated type.