Issues with Items as dictionary keys (only in builds)

msm

New member
Hi,

just had to debug this issue I was facing in a new build I created.

In Inventory (and ShootableWeapon, but the issue is the same), Item objects are used as dictionary keys. Items would get added and later when a lookup is attempted the lookup would fail for what should have been a matching Item object. It doesnt look like Item or its ancestor classes define GetHashCode(), it would just seem like it being a MonoBehavior and whatever GetHashCode() definition comes with that changes over it's lifetime. I googled a bit and it seems like others have encountered this issue (not with UFPS but in general) as well.

This resulted in weapons not being equippable after being picked up and reloads throwing an error. The fix was to replace the Items as dictionary keys with the ItemIdentifier.ID uint values instead.

Has anyone encountered this as well? This only affected me in a the build (both for Mac and UWP builds), NOT in the editor.
Also, I dont believe this was happening before I upgreaded from Unity 2019 to 2020.

Looks like there are more instances in the UFPS codebase of using GameObject or other Unity objects as dictionary keys, Im wondering if I should be changing them all to use GetInstanceID() instead.
 
I haven't seen this occur before - are you able to tell me how to reproduce it within a fresh project?
 
Im not sure how to reproduce it, I only encountered it in a build, and only after upgrading to Unity 2020.

The items are being added to the Inventory, and on item pickup and attempt to equip, I can even print the entire dictionary in Inventory GetItem and it shows a matching item, but the dictionary does not return it. Using the ItemIdentifier.ID as keys is my workaround for now
 
Hmm are you on the latest version of UCC? Definitely haven't seen this issue before either...
 
Top