Closed KarryCharon closed 1 week ago
Godot collections don't use any of the C# comparison/equality methods (GetHashCode
, Equals
, ==
or !=
).
When calling Godot.Collections.Dictionary.ContainsKey
it just calls the native C++ implementation of the Dictionary::has
method which uses the Variant hasher. For GodotObject
and derived types this means calculating a hash from the object's pointer, so naturally different instances will have a different hash.
I'm not aware of any way to override this, so you'll have to convert the Godot collection to a C# collection if you want to use the C# comparison/equality.
Godot collections don't use any of the C# comparison/equality methods (
GetHashCode
,Equals
,==
or!=
).When calling
Godot.Collections.Dictionary.ContainsKey
it just calls the native C++ implementation of theDictionary::has
method which uses the Variant hasher. ForGodotObject
and derived types this means calculating a hash from the object's pointer, so naturally different instances will have a different hash.I'm not aware of any way to override this, so you'll have to convert the Godot collection to a C# collection if you want to use the C# comparison/equality.
C# builtin Dictionary cant be export to Inspector, Godot's Dictionary cant rewrite hash for ContainsKey. Both of them are important for me. :(
Describe the project you are working on
-
Describe the problem or limitation you are having in your project
C# builtin Dictionary and Godot's Dictionary hash behaviors are not consistent.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
-
If this enhancement will not be used often, can it be worked around with a few lines of script?
-
Is there a reason why this should be core and not an add-on in the asset library?
-