Search Unity

ECS job and use of static variables

Discussion in 'Entity Component System' started by OnceUponADev, Jan 12, 2020.

  1. OnceUponADev

    OnceUponADev

    Joined:
    Dec 5, 2018
    Posts:
    12
    Hi all,

    From the documentation
    "Accessing static data from a job circumvents all safety systems. If you access the wrong data, you might crash Unity, often in unexpected ways."

    So I am wondering, does that mean that you cannot use static data INSIDE the job, but still use it on the OnUpdate method? I do not see how this would be a problem, but I really want to make sure before continuing with my project :)

    Thank youuuuuuuu
    ps:
    // OnUpdate runs on the main thread.
    protected override JobHandle OnUpdate(JobHandle inputDependencies)
     
  2. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    You can use static in OnUpdate.
    You can use readonly static of blittables in jobs, which they will be copied.
     
  3. OnceUponADev

    OnceUponADev

    Joined:
    Dec 5, 2018
    Posts:
    12
    thanks a lot :) I can now sleep again hahaah
     
  4. SisyphusStudio

    SisyphusStudio

    Joined:
    Nov 24, 2018
    Posts:
    9
  5. OnceUponADev

    OnceUponADev

    Joined:
    Dec 5, 2018
    Posts:
    12
    oh sweeet, I have focused so much on ECS that I did not even check the documentation for burst! thanks!
     
  6. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    That one is even newer than typing @latest into the URL. I just found it too.
     
  7. quabug

    quabug

    Joined:
    Jul 18, 2015
    Posts:
    66
    I am worry about "static restrict" too.
    At first glance it seems good to limited developer to only access immutable static data in job.
    But in practice, the ability to access "any" kind of data is very helpful in multi-thread program, and it also safe as long as developer initialize static data in its static constructor and never change it.