Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Burst & Particle Sizes

Discussion in 'Burst' started by Piflik, Jul 27, 2022.

  1. Piflik

    Piflik

    Joined:
    Sep 11, 2011
    Posts:
    289
    I am using Burst
    IJobParticleSystemParallelForBatch
    to control particles. I am using position, velocity and age without problems, but when I want to access the particles' sizes, I get null reference exceptions. I have since noticed, that I don't get these exceptions, if I enable "3D Start Size" (which I do not want; the particles should be scaled uniformly).

    Is there an alternative to make it work? I haven't found a mono-dimensional size alternative in the
    ParticleSystemJobData
    class.
     
  2. Piflik

    Piflik

    Joined:
    Sep 11, 2011
    Posts:
    289
    For anyone finding this: if "3D Start Size" is not set, only the x-component of the sizes
    ParticleSystemNativeArray3
    has a value. Without looking at the source one might not realize that the
    ParticleSystemNativeArray3
    is struct that contains 3
    NativeArray<float>
    (x, y and z) and getting a single Vector out of this struct builds it from the respective entries in these arrays. In the uniformly scaled case, the y and z components are null, to save memory, thus building the vector throws a
    NullReferenceException
    .

    This is a long winded way to say: instead of using
    data.sizes
    , use
    data.sizes.x
    .

    I wish the documentation for
    ParticleSystemJobData
    was clearer on that. Alternatively, it would be useful, if the
    ParticleSystemJobData
    contained a get-only property for uniformSizes that directly returns the sizes.x array.