ArgumentException: An item with the same key has already been added.

This is stopping a build! Any ideas? Im using HDRP and unity 2021.2.16f1

ArgumentException: An item with the same key has already been added. Key: -1846274
System.Collections.Generic.Dictionary2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <feaaa6313e32495d9f259b175aa6b597>:0) System.Collections.Generic.Dictionary2[TKey,TValue].Add (TKey key, TValue value) (at :0)
UnityEngine.Rendering.HighDefinition.HDLightRenderDatabase.AttachGameObjectData (UnityEngine.Rendering.HighDefinition.HDLightRenderEntity entity, System.Int32 instanceID, UnityEngine.Rendering.HighDefinition.HDAdditionalLightData additionalLightData, UnityEngine.GameObject aovGameObject) (at Library/PackageCache/com.unity.render-pipelines.high-definition@12.1.6/Runtime/Lighting/Light/HDLightRenderDatabase.cs:156)
UnityEngine.Rendering.HighDefinition.HDAdditionalLightData.CreateHDLightRenderEntity (System.Boolean autoDestroy) (at Library/PackageCache/com.unity.render-pipelines.high-definition@12.1.6/Runtime/Lighting/Light/HDAdditionalLightData.cs:3603)
UnityEngine.Rendering.HighDefinition.HDAdditionalLightData.OnEnable () (at Library/PackageCache/com.unity.render-pipelines.high-definition@12.1.6/Runtime/Lighting/Light/HDAdditionalLightData.cs:3620)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

First couple of things I would try:

  • reimport all, then build

  • make a blank project, copy over Assets folder from yours, see if that builds

  • try switching to a different target (if you have it installed, such as Android, or iOS, or WebGL) and back.

1 Like

Thanks mate will give them a go.

edit: seems like it happens when there are 2 instances of this script added to a light:
HDAdditionalLightData (not sure how that happens though)

fixed it with a small wizard

 HDAdditionalLightData[] xxx =  FindObjectsOfType<HDAdditionalLightData>();
        for (int i=0; i<xxx.Length; i++)
        {
            //DOES IT HAVE 2?
            HDAdditionalLightData[] yyy = xxx[i].gameObject.GetComponents<HDAdditionalLightData>();
            if (yyy.Length > 1)
            {
                _("xxMORE THAN 1 HDAdditionalLightData FOUND ON " + xxx[i].gameObject.name + " AT " + GetGameObjectPath(xxx[i].gameObject));
                //REMOVE IT
                yyy[1].enabled = false;
            }
        }
1 Like

When i enable Editor/Enter Play Mode Options it’s giving this error. But when i become disabled, problem is solved.

1 Like