Search Unity

Single graph handling many effects at different positions/orientations?

Discussion in 'Visual Effect Graph' started by PhilSA, Jun 13, 2021.

  1. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    I'm trying to figure out if VFXGraph makes it possible to have a single "VisualEffect" gameobject handle all instances of the same VFX. Here's an example of what I mean:
    • I make a bullet hit VFX
    • I have a game with tons of bullet hits happening all the time
    • Instead of spawning an entire gameObject (from a pool) everytime a bullet hits something, I'd like to have one single VFX graph where I can call some sort of "myGraph.SpawnHitFXAtPointEvent"
    Is this possible? Currently I have a working version where each bullet hit VFX is a separate GameObject spawned from a pool, but the PostLateUpdate.VFXUpdate() cost in the profiler is really huge. I need something that performs better
     
    Last edited: Jun 13, 2021
  2. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    So far I've reached the point where I sort-of made things work by doing this whenever a bullet hits something:
    Code (CSharp):
    1. myVFX.SetVector3("SpawnPos", vfxRequest.Position);
    2. myVFX.SetVector3("SpawnRot", vfxRequest.Rotation);
    3. myVFX.SendEvent("OnPlay");
    In the graph, I use "SpawnPos" and "SpawnRot" to init the particles in worldspace at the hit transform. This works flawlessly when there is never more than one bullet hit happening every frame, but if there is more than one simultaneous hit (like a shotgun), only one of the bullet hit VFX will play.

    I assume this is because VFXGraph only plays the latest OnPlay call on the next frame where it simulates. I've tried manually calling BulletHitVFXGraph.Simulate() between eash OnPlay even, but it doesn't change anything
     
    Last edited: Jun 14, 2021
  3. JJRivers

    JJRivers

    Joined:
    Oct 16, 2018
    Posts:
    137
    One option would be a custom MultiplePositionBinder will get you to 16k and change (max size for texture width, you could increase it to ludicrous numbers if you come up with a sampler for multiple vertical lines but i have never done that), set hit locations in the texture and count numbers can act as multiplier for how many effects you spawn in the graph. But this is likely not a quick and dirty solution and requires quite a bit of research and optimization work by hand.