non native array variables unaltered in burst job

I noticed that anything that is not a nativearray type variable is unaltered even if the job modifies it.

For example.

[BurstCompile]

struct Job : IJob
{
public bool Ran;
void Execute()
{
Ran = true;
}
}

if I ran this job ran would be always be false.
But if i use a nativearray with 1 element it works fine. Is this a known thing with the burst compiler?

It is known thing for jobs in general. AFAIK anything you want to write to in a job has to be a native container.

1 Like

Ah good to know.

ty

What about simple pointers like int*?

Has nothing to do with jobs, burst or native containers.

It’s because jobs are structs and that’s how structs work.

NativeContainers work because they don’t hold values, they hold a pointer.

    public void Test()
    {
        var t = new MyTestStruct();
        this.Set(t, 9);
        Debug.Log(t.Value); // what is this value
    }

    private void Set(MyTestStruct test, int val)
    {
        test.SetValue(val);
    }

    public struct MyTestStruct
    {
        public int Value;

        public void SetValue(int val)
        {
            this.Value = val;
        }
    }
4 Likes