ArgumentException: An element with the same key already exists in the dictionary.

I get the following error when I try to add an alternative fire to the bow. LMB is assigned to Action-ID-0 for the bow, and ID-1 is assigned to RMB. All properties under shootable weapon and third person shootable weapon properties scripts are the same except the corresponding action IDs. What should I change to be able to use the second one?

One error indicates the player character, and the other one the scheduler. Mainly, when I shoot with ID-0, when I try to shoot with ID-1, it is telling that this key is already used.

Here is the full error:

ArgumentException: An element with the same key already exists in the dictionary.
System.Collections.Generic.Dictionary`2[UnityEngine.Material,Opsive.UltimateCharacterController.ThirdPersonController.Camera.ObjectFader+OriginalMaterialValue].Add (UnityEngine.Material key, OriginalMaterialValue value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404)
Opsive.UltimateCharacterController.ThirdPersonController.Camera.ObjectFader.InitializeCharacterFadeRenderers (UnityEngine.Renderer[] renderers) (at Assets/Opsive/UltimateCharacterController/ThirdPersonController/Scripts/Camera/ObjectFader.cs:602)
Opsive.UltimateCharacterController.ThirdPersonController.Camera.ObjectFader.OnShowProjectile (UnityEngine.GameObject projectile, Boolean show) (at Assets/Opsive/UltimateCharacterController/ThirdPersonController/Scripts/Camera/ObjectFader.cs:625)
Opsive.UltimateCharacterController.Events.InvokableAction`2[UnityEngine.GameObject,System.Boolean].Invoke (UnityEngine.GameObject arg1, Boolean arg2) (at Assets/Opsive/UltimateCharacterController/Scripts/Events/InvokableAction.cs:132)
Opsive.UltimateCharacterController.Events.EventHandler.ExecuteEvent[GameObject,Boolean] (System.Object obj, System.String eventName, UnityEngine.GameObject arg1, Boolean arg2) (at Assets/Opsive/UltimateCharacterController/Scripts/Events/EventHandler.cs:425)
Opsive.UltimateCharacterController.Items.Actions.ShootableWeapon.DetermineVisibleProjectile (Boolean forceDisable) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/ShootableWeapon.cs:823)
Opsive.UltimateCharacterController.Game.ScheduledEvent`1[System.Boolean].Invoke () (at Assets/Opsive/UltimateCharacterController/Scripts/Game/Scheduler.cs:126)
Opsive.UltimateCharacterController.Game.Scheduler.Invoke (Opsive.UltimateCharacterController.Game.ScheduledEventBase scheduledEvent, Int32 index) (at Assets/Opsive/UltimateCharacterController/Scripts/Game/Scheduler.cs:657)
Opsive.UltimateCharacterController.Game.Scheduler.FixedUpdate () (at Assets/Opsive/UltimateCharacterController/Scripts/Game/Scheduler.cs:329)
 
Last edited:
Sure, is this what you mean? Or did you mean I should post this on a bugs thread?

1. UCC
2. 2018.2.5f1
3. Secondary attack for bow is not working.
4. Create a bow weapon for a character. Create a new shootable weapon action (ID=1), and assign it to a new use item ability. Assign action ID=1 for that use ability. Uncheck the Aim item ability to disable it. Copy/paste the properties of the ID=0 bow ability to ID=1 bow ability (shootable weapon) and also to third person shootable weapon properties, and then change action ID's for each component back to ID=1. Try to shoot with left and right mouse button. At this point LMB can still keep shooting, when I press RMB, I can shoot once, but then the player attempts to shoot and the following message occurs:
5.
ArgumentException: An element with the same key already exists in the dictionary.
System.Collections.Generic.Dictionary`2[UnityEngine.Material,Opsive.UltimateCharacterController.ThirdPersonController.Camera.ObjectFader+OriginalMaterialValue].Add (UnityEngine.Material key, OriginalMaterialValue value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404)
Opsive.UltimateCharacterController.ThirdPersonController.Camera.ObjectFader.InitializeCharacterFadeRenderers (UnityEngine.Renderer[] renderers) (at Assets/Opsive/UltimateCharacterController/ThirdPersonController/Scripts/Camera/ObjectFader.cs:602)
Opsive.UltimateCharacterController.ThirdPersonController.Camera.ObjectFader.OnShowProjectile (UnityEngine.GameObject projectile, Boolean show) (at Assets/Opsive/UltimateCharacterController/ThirdPersonController/Scripts/Camera/ObjectFader.cs:625)
Opsive.UltimateCharacterController.Events.InvokableAction`2[UnityEngine.GameObject,System.Boolean].Invoke (UnityEngine.GameObject arg1, Boolean arg2) (at Assets/Opsive/UltimateCharacterController/Scripts/Events/InvokableAction.cs:132)
Opsive.UltimateCharacterController.Events.EventHandler.ExecuteEvent[GameObject,Boolean] (System.Object obj, System.String eventName, UnityEngine.GameObject arg1, Boolean arg2) (at Assets/Opsive/UltimateCharacterController/Scripts/Events/EventHandler.cs:425)
Opsive.UltimateCharacterController.Items.Actions.ShootableWeapon.DetermineVisibleProjectile (Boolean forceDisable) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/ShootableWeapon.cs:823)
Opsive.UltimateCharacterController.Game.ScheduledEvent`1[System.Boolean].Invoke () (at Assets/Opsive/UltimateCharacterController/Scripts/Game/Scheduler.cs:126)
Opsive.UltimateCharacterController.Game.Scheduler.Invoke (Opsive.UltimateCharacterController.Game.ScheduledEventBase scheduledEvent, Int32 index) (at Assets/Opsive/UltimateCharacterController/Scripts/Game/Scheduler.cs:657)
Opsive.UltimateCharacterController.Game.Scheduler.FixedUpdate () (at Assets/Opsive/UltimateCharacterController/Scripts/Game/Scheduler.cs:329)
 
This is likely related to the bow materials that you are using. Can you upload a repro scene that includes the error?
 
I tried to choose none for all materials related to the bow, and the arrow to see if the error would disappear. Apparently, even if I disable all materials on the related objects (including the trail renderer) the message persisted.

Then I tried to add ID=1 components' properties under the bow item one by one (instead of copy pasting from the ID=0 components), and I realized that when I change the Projectile Visibility from On Fire to Always, then I start getting that message. But I also realized that the issue with the bow not shooting in ID=1 was not caused by the error message, and possibly something else when I copy pasted the previous component to the new one. So both action ID's can successfully shoot with the properties assigned to them.

One problem that I still have (and I believe this is related to the issue that you said you may be fixing in the next update) even at instant fire, when the stamina is depleted by the secondary fire mode, it still keeps shooting.
 
Top