Search Unity

Question How do I use VFX to spawn at multiple locations in one frame?

Discussion in 'Visual Effect Graph' started by jjejj87, Jul 1, 2022.

  1. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    1,117
    Hello, I was trying to figure this out but was not successful so far.

    My case:
    I am trying to spawn VFX in specific locations in one frame. I've set it up to call vfx.Play() and I move the vfx transform to set position and set the space of vfx to world and set position to local (0,0,0)

    It works well, except when I call more than one in a frame, in which case it seems to only play once (the last call I think)

    I've come around this issue by making a list of same vfx gameobject and cycling through them but, the more I want to spawn the more vfx gameobject I have to have and I started to think this is not good for performance

    My question:
    Is there a way to do this with 1 vfx and call multiple times in a frame?

    Also, my other question is
    I feed the angle of the vfx gameobject via SetVector("Angle", value) to match the rotation of the vfx transform and it works fine, but is there a simpler way to this?
     
  2. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    Currently VFX graph delays events until end of frame and the last one will be dispatched.
    You can do one of the following:

    1. Use direct link (requires more setup) https://forum.unity.com/threads/new-feature-direct-link.1137253/
    2. Create Texture and set pixels to use them as positions inside the graph. I think it's described here: https://forum.unity.com/threads/multiple-event-burst-spawns-of-the-same-vfxgraph-possible.852049/
    3. Use graphics buffer, very similar to trick with texture, but less hacky and you can pass additional data easily.

    Personally I would go with option 3.

    Sadly angle is often not flexible and there are no functions or quaternions to play with it in friendly way.
    Most of time Orient block is enough to "rotate" particles in the way you need, but if you need custom direction you can pass rotation with event
    vfx.SendEvent("OnPlay", attributes);
    (or buffer in option 3). You could also pass direction or target position and orient them based on this - many options, but it all depends how your VFX works.
     
  3. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    1,117
    Thank you for the detailed answer! Much appreciated!