Search Unity

Set a job input by reference

Discussion in 'Entity Component System' started by jdtec, Aug 22, 2019.

  1. jdtec

    jdtec

    Joined:
    Oct 25, 2017
    Posts:
    302
    I am currently passing an int counter into a job inside of a NativeArray so that the value can be set in the job then read back after the job is completed.

    Is there a cleaner way to do this?
     
    Antypodish likes this.
  2. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,709
    I ran into a similar issues but never thought of using a native array as a work around.
     
  3. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    JobHandle.IsCompleted
     
    florianhanke likes this.
  4. jdtec

    jdtec

    Joined:
    Oct 25, 2017
    Posts:
    302
    I'm not sure how that helps me - I am completing the job already.

    I can pass it in by value like 'int counter' and it will write to a copied value in the job or I can do the hack I'm currently doing and pass it in by 'NativeArray<int> counter' which is set to just size of 1 and contains the counter value so I can set by reference and then read the value back outside the job.
     
  5. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    I am sorry, I misread the question... NativeArray is one way. int* is another. NativeArray is more robust / safety system.

    int* is more efficient but easy to make mistake and cause crashes with, when you don't have a full understanding of how GC & stack works.

    We should probably introduce NativeValue for this purpose...
     
    digitaliliad, JesOb, jdtec and 4 others like this.
  6. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    492
  7. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,709
    Oooo boy ! This will simply some thing in my code for sure
     
  8. jdtec

    jdtec

    Joined:
    Oct 25, 2017
    Posts:
    302
    That sounds good.

    It's encouraging to see the CTO being so hands-on with the tech.
     
  9. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356