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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Question Pooling VFX Graphs

Discussion in 'Visual Effect Graph' started by leohilbert, Jul 5, 2023.

  1. leohilbert

    leohilbert

    Joined:
    Nov 28, 2015
    Posts:
    17
    Hi all,
    I'm currently developing a pooling system for our VFX objects. Currently we just instantiate the VFX Graphs (Prefabs) whenever they are needed (Attacks, Explosions, Impacts, etc) and destroy them again afterwards.
    This can't be good for performance and since we are also aiming for lower end devices, I want to do something about it.
    I see 2 ways to approach this pooling and wanted to ask if anybody has experience and/or an opinion to share :)

    1. One Pool per Effect
    Every Visual Effect Asset gets its own pool. Each pool probably only has a capacity of 1 or 2, since they are only triggered rarely. Once one is needed it gets enabled and returned to the pool afterwards

    2. One Pool for all simple VFX Effects
    Most of our VFX Graphs don't have any scripts/configurations apart from the configured SortingLayer. They should just play once and deactivate again. For these I can imagine to have one common Pool with Gameobjects that only contain one "Visual Effect" Component. When taking them out of the Pool we just swap out the "Asset Template" and "Sorting Layer" and play them.

    Using approach 2 would allow us to have way less VFX Components, because I don't think there are ever more than 3 vfx playing at the same time. Using approach 1 would require us to have at least 1 Pool&GameObject per effect that is used in the Scene, so it can add up quickly.

    Is there a big cost associated to swapping out Asset Templates of VFX Effects? I could imagine some internal caches/pools being invalidated every time we swap out asset, especially if the type of effects can be quite different.

    At the end of the day it probably comes down to measuring it myself, but I wanted to get an understanding of the underlying mechanics first.

    Thanks :)
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,415
    Recent unity versions (at least 2022lts, not sure about 2021) will instance VFX graphs as well. This means that if multiple of the same graphs are loaded, they are batches together.

    Next to that, do you have a measurable performance issue? If not, just keep it as is for now.
    If you do, best I can say is to make very rough setups for the vfx and benchmark it.
    The profiler, frame debugger, and for mobile render doc are good tools
     
    leohilbert likes this.
  3. Duckocide

    Duckocide

    Joined:
    Aug 30, 2014
    Posts:
    35
    I've used a pooling technique where I have one VFX Graph per room for a particular VFX effect. I'm using them a lot for scene object rendering / room decoration now and just have appropriate colliders on the gameObjects. Anyway, I've found you can repeatedly call Play() on a VFX graph to spawn fresh particles provided you ensure a frame has occurred between calls (guessing the unity code squirts graph parameters in at end of frame and of course executes the OnPlay event which triggers a new initialise). I've used it to good effect in my procedural dungeon rooms and avoided lots of "VFX" graph prefabs (e.g. Drawing a breadcrumb trail of things around a scene room). ... I'm using VFX Graph 14.0 in 2022 LTS

    I should just add that I'm using coroutines a lot so that I can pseudo parallelise the repeated calls to VFX Graphs and get that all important frame refresh between parameter changes and play().
     
    leohilbert likes this.