Search Unity

Params in Jobs

Discussion in 'Entity Component System' started by PublicEnumE, Mar 16, 2019.

  1. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    I assume there's no safe way to use the 'params' keyword from inside a Job. Calling out to a method that takes a params array would...allocate an array, and therefore wouldn't be blittable. :p

    Still, the params syntax is mighty useful. And the size of the array could be known at compile time. So I was wondering if anyone has found a way around this.

    I don't believe there's any way to use a custom collection type with the params keyword (MS Docs seem to suggest it's hardcoded to only every use an array). But maybe I'm mistaken?
     
  2. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    Why don't you use a NativeArray of whatever you want to pass in? Sure the syntax might be slightly less appealing, but from my understanding, params has always been horrible for performance due to the garbage generation anyway.
     
    PublicEnumE likes this.
  3. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    That's really the only reason someone might want to. :p

    I haven't used them in general (using Native Collections instead), because at the end of the day, perf usually comes first.

    Just wondering if anyone's come up with a good way that doesn't also sacrifice performance. :)