Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

Discussion in 'Burst' started by Antypodish, Aug 2, 2019.

  1. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,754
    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
    Code (CSharp):
    1. public const int i_hundred = 100 ;
    But I can not have float3 as constant for example.
     
    Last edited: Aug 2, 2019
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,754
    Oki, I will approach this problem with different question.
    What would be best approach, to use global variables with burst / jobs?
     
  3. Rom-

    Rom-

    Joined:
    Nov 26, 2008
    Posts:
    90
    Antypodish likes this.
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,754
    Thx.
    I see static (readonly) / constant data access has been changed, since Unity 2019.x.
    Anyway, I modified these data accordingly yesterday.
     
  5. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    As a workaround for now you can provide all x, y, z parameters in the static readonly constructor. That seems to work.
     
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,754
    Thank you Joachim. That seams works nicely so far.
    At least I don't need pass constants via jobs boiler plates.

    My simplified example.
    Code (CSharp):
    1. static public class Constants
    2. {      
    3.         static readonly public float halve ;
    4.  
    5.         // Auto load constants.
    6.         static Constants ()
    7.         {        
    8.             halve = 0.5f ;
    9.         }
    10. }
     
  7. tim_jones

    tim_jones

    Unity Technologies

    Joined:
    May 2, 2019
    Posts:
    287
    @Antypodish thank you for reporting this. For now you can use @Joachim_Ante's workaround, and we'll fix the bug in Burst in the next release.
     
    Antypodish likes this.
  8. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,754
    Thank you. Mostly appreciated for taking work on board.
     
  9. sheredom

    sheredom

    Unity Technologies

    Joined:
    Jul 15, 2019
    Posts:
    300
    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:

    Code (CSharp):
    1. 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!
     
    Deleted User and Antypodish like this.