Let’s first describe the setup. I have a custom struct “MyStruct” that has a generic parameter “T” which is constrained to be a ‘struct’. I now want to use “MyStruct” as value inside a NativeParallelHashMap. Setup looks like this (simplified):
public struct MyStruct<T> where T : struct
{
public T MyContent;
}
— Inside another method —
public NativeParallelHashMap<int, MyStruct<T>> MyMap;
In this other method, “T” is also constrained to be a ‘struct’.
This setup worked fine until I updated from Unity ‘2023.2.20’ to the newest Unity 6 (currently: 6000.0.28f1). Now I get an error on compilation:
Error CS8377: The type ‘MyStruct(T)’ must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter ‘TValue’ in the generic type or method ‘NativeParallelHashMap<TKey, TValue>’
Any idea, workaround or fix? I tried using “notnull” instead of “struct” as a generic constraint, but that does not change anything.
I understand that Unity cannot know, if the actual implementation of “T” does not contain any nullable fields at this point, but having a solution that does not fail at compilation (like it did before updating) would be great.
Thanks!