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.

Showcase Solution for Handling Multiple SendEvent() per frame (2020.3/2021.3)

Discussion in 'Visual Effect Graph' started by peeweekVFX, Oct 23, 2022.

  1. peeweekVFX


    Oct 19, 2015

    I'm dropping a message here so maybe it could be useful to someone.


    I've recently added two C# custom spawners to my open source VFX Graph Extras project. These blocks enable managing multiple events incoming on a spawn context at the same frame, while keeping each event's VFXEventAttribute state :

    - One is called Burst Multiplex FIFO, and handles multiple burst of particles
    - Other is called Rate Multiplex FIFO, and handles rate of particles as multiple sources.

    Of course if you don't want to install the whole package, you can get these files here:

    Disclaimer and limitations

    1) Use only for Low-Scale :These blocks does not have a goal of being a large-scale solution, and is probably less efficient than having a fully-fledged solution. While these can handle few events each frame, they are not intended for handlings hundreds/thousands of events.

    Correct built-in solutions could be -for instance- having a synchronous SpawnEvent context to be used in direct link (for instance to handle various spawn counts in particle systems on a single direct link event), or virtualize spawn contexts to handle rate correctly.

    2) Incorrect Reading of Event Attributes in Operators: The values you read in the graph from the Attributes in the spawn context will be incorrect.
    Explanation : As these blocks iterate/cycle through a list of VFXEventAttribute, they change the block's VFXEventAttribute state and thus, the values you read are always one frame late, so you don't read the value of the current event/source, but the one from the previous iteration.

    3) Do not mix with other spawn burst/blocks :The behaviour would be rather unknown. I advise you only use one Rate/Burst multiplex per context only. You can still use Set EventAttribute blocks though, it seems to work.

    How does it work (TLDR):


    Burst Multiplex FIFO records any incoming event hitting the start of its spawn context. For each event, it stores both the VFXEventAttribute state, and the spawnCount attribute. Every frame, it dequeues 1 element of the queue and outputs a SpawnEvent with the correct state, and the spawnCount attribute multiplied by the Count Scale.

    That means that 30 incoming events will be processed in 30 frames.

    Hitting Stop clears the queue.


    Rate Multiplex FIFO records any incoming event hitting the start of its spawn context. For each event, it creates internally a "Source" that will live for some time (defined by the Source LifeTime property). At update, every frame the system cycles through sources, updates each source internal source lifetime, and outputs based on the SpawnRate property. If the source is too old, it is removed from the alive source list.

    That means that 30 incoming events will result in 30 sources, each one processed each frame, so a full cycle of update will take 30 frames.

    Hitting Stop stops all sources.
    Last edited: Oct 23, 2022