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

Question vfx: spawnIndex spawnCount relation

Discussion in 'Visual Effect Graph' started by automat, Dec 23, 2021.

  1. automat

    automat

    Joined:
    Dec 22, 2016
    Posts:
    2
    Hello there,

    I´m trying to correctly understand the relationship between spawnIndex and spawnCount.

    Simple test setup: spawn random amount, normalize particle spawn index by spawn count and map to particle position to create a straight line, (index/max(count-1, 1)). I would expect the positions within a spawn group to be evenly distributed on a line, with index 0 at the start and index count-1 at the end of the line. But I´m observing missing particles at the end of the line. What am I missing here?

    upload_2021-12-23_11-6-27.png upload_2021-12-23_11-7-44.png
     
  2. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Heya,

    spawnCount is a float, so you will get some imprecision if you are trying to math it out like this:


    If you floor its value however, your should get a consistent results between similar counts:


    The count is going to be larger than the largest index as well (i.e. if you spawn a burst of 2 particles, you will have a count of 2, but your individual particles will have a spawnIndex of 0 and 1. If you divide them by 2, your first particle will be at the start (0/2 = 0), but the second one will be in the middle (1/2 = 0.5).

    If that's not what you want, you can also subtract 1 from your count and your particles will be evenly spaced on both sides:


    Hope this helps!
     

    Attached Files:

    daneobyrd likes this.
  3. automat

    automat

    Joined:
    Dec 22, 2016
    Posts:
    2
    @vladimirneykov makes sense with the precision error, works like a charm. Thank you!
     
    VladVNeykov likes this.
  4. daneobyrd

    daneobyrd

    Joined:
    Mar 29, 2018
    Posts:
    101
    How does spawnCount relate to spawnIndexInStrip? I had tried using spawnCount with a Heads and Trails system but it seemed like the spawnCount (Source) for a GPU Event (using Trigger Event Always) would always be the number of strips that spawned that frame. I was thinking spawnCount would refer to the the number of particles within that strip that spawned that frame.