I’m on Unity 2022.3 , Burst 1.8.17, Collections 2.5.0 pre2
Seems like Burst doesn’t like calling schedule to Generic Jobs inside Bursted code.
Found this which is somehow related. SortJob with IComparer. but since the thread is closed since 2021, and nobody is mentioning this error, I was a bit lost.
I’m trying to call NativeArray.SortJob<T,U> (type and comparer) on a type that is generic too. And It complains by saying this:
InvalidOperationException: System.InvalidOperationException: Reflection data was not set up by an Initialize() call. Support for burst compiled calls to Schedule depends on the Collections package.
I know there’s something about Generic Jobs in the docs, and that it can be solved by defining the specific types on the assembly by adding this attribute: [assembly: RegisterGenericJobType(typeof(NativeArray<MyGenericStruct<A,B>>.SortJob))]
It is also done automatically if you create the Job and storing it on a var, then call Schedule separately.
My problem is that SortJob is in NativeArray’s class. I can’t add that attribute on top.
I also tried doing the very very specific call with types and storing on a variable. It doesn’t want it too (??).
So how do I use that attribute or make this work? Is there any new solution to this? Is there any way to use SortJob on Burst at all?
Ah, that’s another option, yes. I didn’t think of it.
But the array could have maybe 100.000 items. And each item contains a bunch of data. Sorting structs is not fast. It contains an ID and some other data that changes depending on the type.
I was doing a Radix Sort on just the indices array (or a basic sort) then organize the rest with the final positions. How about that?
Erm. I couldn’t place the attribute somewhere else. I received an error that I wasn’t placed on top of the job. Maybe I misunderstood. Let me have a look at that and I’ll come back. Thanks!
But I get that the second generic type (in SortJob<T,U>) , it can’t be that because it has no boxing conversion from that type (comparerstruct<etc…>) to ID’s IComparer. ¿¿¿