NativeHashSet which is built on top of NativeHashMap accepts only unmanaged type

Hello,

As the title says, NativeHashSet is built on top of a NativeHashMap, it’s only a wrapper.
NativeHashMap accepts struct type for his generics arguments

So why NativeHashSet doesn’t do the same ? :eyes:

NativeHashMap also only accepts unmanaged type IRC.

The code doesn’t said that

Well, it does give runtime error: ArgumentException: TestSystem+MyStruct used in native collection is not blittable, not primitive, or contains a type tagged as NativeContainer
```csharp
*using System;
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;

public class TestSystem : SystemBase
{
private struct MyStruct : IEquatable
{
public object o;

    public bool Equals(MyStruct other)
    {
        return Equals(o, other.o);
    }

    public override bool Equals(object obj)
    {
        return obj is MyStruct other && Equals(other);
    }

    public override int GetHashCode()
    {
        return (o != null ? o.GetHashCode() : 0);
    }
}

protected override void OnUpdate()
{
    NativeHashMap<MyStruct, byte> m = new NativeHashMap<MyStruct, byte>(0, Allocator.Temp);
}

}*
```

because you using an object inside. Unmanaged means ( in this context with burst compiler) you can’t have pointer inside your struct however struct allows pointer. Can be handy when your T argument have a blob reference inside.

unmanaged constraint doesn’t prevent you from having pointers:

Seems like an issue with BlobAssetReference itself, for some reason it is not unmanaged

indeed :face_with_spiral_eyes: curious to have an answer from unity team

2 Likes

Bump