From 9f57fcf33298944fb42cdf760b593896c502eb11 Mon Sep 17 00:00:00 2001 From: Soraphis Date: Wed, 19 Jul 2023 17:32:13 +0000 Subject: [PATCH] fix: replaced TryAdd call to support lower .NET versions --- Packages/Core/Editor/Editors/AtomGeneratorEditor.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Packages/Core/Editor/Editors/AtomGeneratorEditor.cs b/Packages/Core/Editor/Editors/AtomGeneratorEditor.cs index 1d01a8c2..81203cd5 100644 --- a/Packages/Core/Editor/Editors/AtomGeneratorEditor.cs +++ b/Packages/Core/Editor/Editors/AtomGeneratorEditor.cs @@ -245,7 +245,11 @@ namespace UnityAtoms.Editor parent.AddChild(dropdownItem); // Use Hash instead of id! If 2 AdvancedDropdownItems have the same name, they will generate the same id (stupid, I know). To ensure searching for a unique identifier, we use the hash instead. - if (!idTypePairs.TryAdd(dropdownItem.GetHashCode(), type) && type.FullName != idTypePairs[dropdownItem.GetHashCode()].FullName) + if(!idTypePairs.TryGetValue(dropdownItem.GetHashCode(), out var preExistingType)) + { + idTypePairs.Add(dropdownItem.GetHashCode(), type); + } + else if(preExistingType.FullName != type.FullName) // type already exists, but it might be just the type itself (e.g. happens for me when using a ECS project) { Debug.LogError($"Could not add '{type.FullName}' to list, because it had a hash collision with: {idTypePairs[dropdownItem.GetHashCode()].FullName}"); }