TMap<TWeakObjectPtr<UObject>, TID>::Find(AnyInvalidObject) should not return a value

Hi,

We encountered this issue on FNetGUIDCache::NetGUIDLookup. This leads to problems down the line because the returned FNetworkGUID is already reassigned to another valid object in our version of the engine (we did not modify map and pointers).

If we understood the issue correctly, FWeakObjectPtr::operator== returns true when both pointers are invalid. Even if the pointers were not actually pointing to the same object when they were valid.

When we define the map, is it possible to use another equal operator (or change operator==) that would, for instance, compare the FWeakObjectPtr::ObjectIndex and FWeakObjectPtr::ObjectSerialNumber?

Our current workaround is to make a special case for invalid pointers before calling Find().

Thank you for your help.

Best regards.

Damien

Steps to Reproduce
Add objects to the map.

Make some of the objects become invalid.

Call Find(X) where X is an invalid object that is not in the map.

Observe that Find returns a value.

Expected behavior, Find should return nullptr.

Hi,

You should find this other post interesting: [Content removed] It discusses various type of Keys for map and set. Toward the end, it also mention using TWeakObjectPtrMapKeyFuncs/TWeakObjectPtrSetKeyFuncs, which is probably what you are looking for.

Regards,

Patrick