How to use NativeMultiHashMap.GetUniqueKeyArray?

I’m super interested in the new GetUniqueKeyArray feature. Though, looking at the source I’m confused about what it returns with Tuple<NativeArray, int>.

Thanks.

1 Like

NativeArray can contain not unique keys, so tuple used to return the array with the count of the unique keys (also it’s the index of the not unique keys), so you need to use a second value of the tuple instead of the array length.

            var (keys, length) = hash_map.GetUniqueKeyArray(Allocator.Temp);
            for (int i = 0; i < length; i++)
            {
                var key = keys[i];
                // get items by key
            }
6 Likes

Considering this thread is over three years old and it’s still the best documentation for this function, I think we need someone at Unity to improve the docs ASAP.

Looks like the links to this whole collection type are broken: Collection types | Collections | 2.1.4

Thanks for explaining it here, saved me some time today.

2 Likes