Valheim-Modding / Jotunn

Jötunn, the Valheim Library.
https://valheim-modding.github.io/Jotunn/
MIT License
128 stars 40 forks source link

Error duplicate key #433

Closed ZenDragonX closed 6 months ago

ZenDragonX commented 6 months ago

An error is occurring when cloning an existing GameObject and the Awake event is run on VisEquipment because ExtEquipment is not checking if it was already added before attempting to AddComponent(). Therefor the Instantiated clone object is raising a duplicate key error. This is reproducible with ArmorStands if you try to clone them.

Suggested fix: Add a TryGetComponent to the Awake method to prevent duplicates.

if (!TryGetComponent<ExtEquipment>(out _)) AddComponent<ExtEquipment>()

[Error : Unity Log] ArgumentException: An item with the same key has already been added. Key: Player Pose (VisEquipment) Stack trace: System.Collections.Generic.Dictionary2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <17d9ce77f27a4bd2afb5ba32c9bea976>:0) System.Collections.Generic.Dictionary2[TKey,TValue].Add (TKey key, TValue value) (at <17d9ce77f27a4bd2afb5ba32c9bea976>:0) Jotunn.Utils.ExtEquipment.Awake () (at D:/Projects/Jotunn/JotunnLib/Utils/ExtEquipment.cs:230) UnityEngine.Object:Instantiate(GameObject)

https://github.com/Valheim-Modding/Jotunn/blob/43f22c7c7b47489f183341b54db9c017d348f77d/JotunnLib/Utils/ExtEquipment.cs#L26C1-L30C10

MSchmoecker commented 6 months ago

Thanks for the report, fixed in 2.20.1