Burst (1.1.0+) Global variable initializer type does not match global variable type!

In Unity 2019.2 with burst 1.1.0+ I got following error (wan’t a problem in 2018.2)

I have struct with

As I mentioned, it worked in burst jobs with Unity 2018.2.

How to fix it?

Edit:
I access variables directly in the job execute, rather than passing via Update to a job, like with other struct.
I just would like have them global, like constants.
I.e. I got

public const int i_hundred = 100 ;

But I can not have float3 as constant for example.

Oki, I will approach this problem with different question.
What would be best approach, to use global variables with burst / jobs?

In the documentation here:

https://docs.unity3d.com/Manual/JobSystemTroubleshooting.html

It states that global variable access from jobs is prevented for safety reasons.

1 Like

Thx.
I see static (readonly) / constant data access has been changed, since Unity 2019.x.
Anyway, I modified these data accordingly yesterday.

As a workaround for now you can provide all x, y, z parameters in the static readonly constructor. That seems to work.

Thank you Joachim. That seams works nicely so far.
At least I don’t need pass constants via jobs boiler plates.

My simplified example.

static public class Constants
{      
        static readonly public float halve ;

        // Auto load constants.
        static Constants ()
        {         
            halve = 0.5f ;
        }
}

@Antypodish thank you for reporting this. For now you can use @Joachim_Ante_1 's workaround, and we’ll fix the bug in Burst in the next release.

1 Like

Thank you. Mostly appreciated for taking work on board.

Hey @Antypodish - thanks for finding this bug!

The bug is basically that our static readonly goes through a constant creation path that isn’t respecting the constructor of the float3. We’ll fix in a future burst version.

As a workaround for now you could do:

static public readonly float3 f3_halve = new float3 ( 0.5f, 0.5f, 0.5f ) ;

EG. initialize each field instead of relying on the float3 splat constructor.

Sorry for the inconvenience, but I’m on the fix!

2 Likes