Search Unity

Question VFX Capacity and performance.

Discussion in 'Visual Effect Graph' started by koirat, Nov 27, 2020.

  1. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,074
    I have noticed that increasing Capacity on "Initialize Particle" block (to some huge number) reduces performance (FPS) even when spawn rate is very small and there are only few particles.

    So as I should understand it is performance efficient to keep capacity as small as possible.
    Now I would like to take into consideration my spawn rate and max lifetime of my particle to calculate the best capacity size.

    As I see right now I cannot change capacity inside VisualEffect graph but can I do it outside of it at runtime.
    Also what if I got exposed properties of lifetime and different effects sharing same VisualEffect.
    Is capacity shared among the same VisualEffects or can I override it per objects on scene ?
     
    RendergonPolygons likes this.
  2. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Yes, the VFX Graph needs to allocate the memory for the potential max capacity you've specified.

    In Target Visual Effect GameObject panel there's a debug option. Leave your effect to play for a bit and you'll see the max number of capacity you need based on your emission and lifetime. This can help decide how much you need.


    Capacity is currently immutable, it's set within the VFX Asset and cannot be changed during runtime.
     

    Attached Files:

  3. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,365
    why does one allocation at instantiation negatively affect FPS during the life of the VFX (I think that's what @koirat meant)?
     
    TokyoWarfareProject likes this.
  4. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,074
    1. Does VFX do calculations for Particles that are not present ? Capacity 1M particles but I spawn only 1 , will other 1M-1 calculations going to be processed ?

    2. Capacity should be mutable :) . Than we can estimate max possible particles by spawn rate and max or average particle lifetime. May I ask the reason why it is not mutable (I guess it is a technical stuff)?
     
  5. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    I'm not sure, to be honest, so I asked the dev team:
    As for the capacity, we have a task for this, but still have to see how to implement it (fixed per instance, growable only...). and how it will work with other upcoming work.
     
    ekakiya, koirat and PutridEx like this.
  6. JJRivers

    JJRivers

    Joined:
    Oct 16, 2018
    Posts:
    137
    Has to do with memory allocation, unless you want it to be possible to make VFX Graphs that just keep growing and growing if you make a single mistake in reaping them, until it hogs your customers RAM for breakfast
     
  7. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,074
    Actually auto-growth would not be such a bad idea.
     
  8. JJRivers

    JJRivers

    Joined:
    Oct 16, 2018
    Posts:
    137
    Ok imagine this situation, some hapless user makes a graph that doesnt reap the particles ever, the allocation just keeps growing until few hours into playmode the game crashes, propably with zero easily interpreted indication of What caused it. Versus good design where you spawn prefab clones of effects to handle X amount of effects, use manual graph instancing to handle multiple effects, use switch to decide which particles to update etc. And never suffer an ever expanding ball of slime.

    Mind you if they can make it sensible and functional i'm all for it.
     
  9. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,074
    All this kind of leak bugs are already possible in C# and it is understandable
    They can do max capacity + auto-growth.
    Then when you design a particle effect you don't have to worry about max particles count.
     
    TokyoWarfareProject likes this.
  10. JJRivers

    JJRivers

    Joined:
    Oct 16, 2018
    Posts:
    137
    As i said, if they can make it function without performance spikes when allocating more capacity im all for it though it will definitely need a warning in the docs about that.
     
  11. YuriyPopov

    YuriyPopov

    Joined:
    Sep 5, 2017
    Posts:
    237
    Sorry to ask like this but what version of the vfx graph has this debug info ? We are on 7.3.1 on URP and I kind seem to find it.
     
  12. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hey @YuriyPopov ,
    Are you referring to the debug modes to see how many particles are alive?
    If so, I believe this was introduced in the 10.x cycle. There's an aliveParticleCount API you can potentially use to check how many particles are alive if you'd like to compare to your capacity and see how efficient your systems are.

    There's a small latency to get the information, but it should be enough to eyeball a good capacity number.
     
    laurentlavigne likes this.
  13. YuriyPopov

    YuriyPopov

    Joined:
    Sep 5, 2017
    Posts:
    237
    Thank you for the clarification :) .
     
    VladVNeykov likes this.
  14. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,091
    Is there a way to allocate memory for capacity after Instantiate when pooling VFXs? Should I use Reinit(), maybe Play/Stop or does it happen in VFX Awake?
     
  15. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,074
    It's been about 2 years and we're back on topic.

    I do not know how this vfx system is working internally so my request might be totally out of place.
    But I find it very troubling that we cannot set VFX capacity at runtime or at least on VisualEffect Component in Edit mode.

    I and probably many people have this problem that we want to be able to keep the density of our particles constant even as we scale our system.
     
  16. cn41

    cn41

    Joined:
    Mar 29, 2022
    Posts:
    2
    I'm using VFX graph to render a point cloud, meaning I know exactly how many particles I need for each instance of the visual effect, and that never changes over the lifetime of the effect.

    Just being able to set the capacity once at start would be great for my needs - otherwise I need to create variations of the graph with 100k, 1m, 5m... particles capacity, or just set the max capacity high enough for the highest expected vert count point cloud - which seems like a waste of memory
     
    Last edited: Jun 29, 2023
    sliwowitz and OrsonFavrel like this.
  17. Charlicopter

    Charlicopter

    Joined:
    May 15, 2017
    Posts:
    125
    Same here. I have many instances of an effect that can be instantiated at various scales, where I need the particle density to remain constant. The maximum density might call for something like 100000 particles, while others may call for 1500. It is constantly bogging my performance.
     
    sliwowitz and cn41 like this.
  18. sliwowitz

    sliwowitz

    Joined:
    Jan 23, 2017
    Posts:
    1
    We use the VFX graph to render many point clouds, up to about one hundred - scanned or live coming from 3D sensors. We have about five different ways of rendering the point cloud, so ideally, we would use five VFX assets applied to hundreds of individual point cloud objects. The number of particles in the source point cloud varies between lower thousands to over a million.

    We know the exact number when we put the point cloud + VFX object in the scene, so in our case, we don't even have to change the effect on runtime - if the calculation can be done in the editor, the number won't change while running - but we need a way to assign the same graph, differing only in the particle capacity, to different objects.

    Doing it manually is impossible now - we would have to duplicate the graph a hundred times, change the particle count for each, and then do all of it again whenever we make any minor change in the graph itself.
     
    Zarbuz and Charlicopter like this.
  19. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    194
    Dynamic Capacity would be very valuable for different setups and to extend re-usability of the VFX Graph assets
    I don't have a good answer for you, but what you could do, is to create "Presets" VFX Graph. Maybe you can create 3- to 6 VFX Graph with different capacity count from low count to High capacity count. This way, based on your Point clouds Count, you can use the closest VFX Graph presets. While not ideal, it would allow saving some memory performance without the need to create a hundred variation of the same VFX Graph asset...
     
    rustinlee likes this.