#Why isn't this Generic Job using Burst?

1 messages · Page 1 of 1 (latest)

craggy karma
#

From my understanding as long as you manually define the types when you create the Job it should work with Burst.

Here is the Job I am attempting to use, and it is marked as BurstCompiled:

[BurstCompile]
public struct ECTParallelJob<MyData> : IJobParallelFor where MyData : unmanaged, IParallelData<MyData>
{
    public NativeArray<MyData> DataArray;

    public void Execute(int index)
    {
        DataArray[index] = DataArray[index].Execute();
    }
}

Here's how I'm creating the job (Data is an unmanaged struct):

public override ECTParallelJob<Data> CreateJob(NativeArray<Data> data) => new ECTParallelJob<Data>(data);

As you can see in the following screenshot, it is showing in the Burst Inspector.

I'm getting the following warning still, even though the job is NOT defined in a generic class, and I AM instantiating the job with concrete types:

This may be because the [BurstCompile] method is defined in a generic class, and the generic class is not instantiated with concrete types anywhere in your code.

Help would be much appreciated, thank you!

#

Why isn't this Generic Job using Burst?

ocean falcon
#

You need to create specific type of job with concrete generic type or use assembly attribute to define it

grim imp
craggy karma
#

Maybe I'm just dumb with this, still getting the hang of Jobs

ocean falcon
#

but it must be compile time

#

by the time your code with generic job runs

#

no constructor or type will be accessible

#

for that specific job

craggy karma
#

Ok, I got it working, but for some reason it only recompiles after restarting the editor

#

Which is really annoying

#

Once again, maybe I'm just doing something wrong, but it is still frustrating

#

If I make changes, it starts throwing the same error as before, but after restarting Unity it works again

#

Here's my Job

#

Here is how I define my job

#

And here is JobData

ocean falcon
#

either explicitly define job as new type

#

or use assembly attribute to register your generic

#

the way you define job will not be compiled by burst

craggy karma
ocean falcon
#

struct MyJob : GenericJob<SpecificType>

#

or

#

[RegisterGenericJob(typeof(smth))] on namespace

#

not sure how attribute correctly is written

#

look at manual Dani provided

craggy karma
ocean falcon
#

😅

#

such explicit declaration with BurstCompile attribute

#

is literally the only way

#

or assembly attribute

#

that's it

#

once again - take a look at manual

#

it has answers and examples on your question

craggy karma
#

Damn, that sucks because I was trying to override the override function for my generic job since it will be used the exact way for all of those inheriting it

ocean falcon
#

you might just reinterpret arrays

#

you pass into job

craggy karma
#

Are you sure you can't have generic Jobs that are structs?

#

I swear I saw people doing this online @ocean falcon

old mist
#

yes, you can. in your screenshots, you didn't define IParallelData<T>; what is that?