Search Unity

Help Wanted cost of instantiating a vfx vs a shuriken?

Discussion in 'Visual Effect Graph' started by laurentlavigne, Apr 13, 2021.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,295
    anyone ran some benchmarks on that?
    instantiation cost of vfx vs shuriken, i'm about to convert over
     
  2. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    1,089
    I would shift anyway, in worst case you can do pooling, with VFX it is trivial.
     
  3. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    442
    Until this improvement is implemented, there will be additional overhead of having many instances of the same VFX compared to Shuriken. If you find that you are hitting some performance issues, you can use 1 master VFX and send events to it with the position and other settings of where the "instances" of the effect should spawn.
     
  4. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,295
    Good point, everything is pooled in this game anyway but resurrecting's a shuriken isn't automatic so what's more trivial with vfx?
    Here is how I do it in shuriken
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. #pragma warning disable 618
    4. // Controls shuriken particle systems within this object, sticks the collisionPlane transform to the ground if specified, recycles after 'destroyIn' seconds.
    5. public class ParticleControllerShuriken : MonoBehaviour
    6. {
    7.     public float destroyIn = 3;
    8.     public Transform collisionPlane;
    9.  
    10.     // Use this for initialization
    11.     void Start()
    12.     {
    13.         if (destroyIn > 0)
    14.             Invoke("Recycle", destroyIn);
    15.         if (collisionPlane)
    16.         {
    17.             if (Physics.Raycast(transform.position, -Vector3.up, out var hit, 1 << LayerMask.NameToLayer("GROUND")))
    18.                 collisionPlane.position = hit.point;
    19.         }
    20.     }
    21.  
    22.     void OnExploding()
    23.     {
    24.         transform.parent = null;
    25.         Invoke("Recycle", Mathf.Max(0, destroyIn));
    26.     }
    27.  
    28.     public void OnRecycling()
    29.     {
    30.         transform.parent = null;
    31.         foreach (ParticleSystem p in GetComponentsInChildren<ParticleSystem>())
    32.         {
    33.             p.enableEmission = false;
    34.             p.gameObject.SetActive(false);
    35.         }
    36.         transform.position = Vector3.up * -1000;
    37.     }
    38.  
    39.     void OnReviveRecycled()
    40.     {
    41.         foreach (ParticleSystem p in GetComponentsInChildren<ParticleSystem>())
    42.         {
    43.             p.enableEmission = true;
    44.             p.gameObject.SetActive(true);
    45.         }
    46.         if (collisionPlane)
    47.         {
    48.             if (Physics.Raycast(transform.position, -Vector3.up, out var hit, 1 << LayerMask.NameToLayer("GROUND")))
    49.                 collisionPlane.position = hit.point;
    50.         }
    51.         if (destroyIn > 0)
    52.             Invoke("Recycle", destroyIn);
    53.     }
    54.  
    55.     void Recycle()
    56.     {
    57.         RecycleManager.Recycle(gameObject);
    58.     }
    59. }

    Oh yeah that makes even more sense. so far I've only used VFX as a drop in replacement for shuriken. And I always get super confused with the local v. world coordinate system. Actually I remember trying that a few lifetimes again and the problem was moving emitters didn't work well at all unless I got the vfx component on what's moving (think smoke trail).

    Got an example of one-off position event and moving emitter I can copy paste?
     
  5. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    1,089
  6. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,295
    I just tested with 33 very mild vfx and vfx indeed has overhead issues: With no more than 4 on-screen the switch drops from 60 to 40fps!!
    Bounds are small so they are culled, normally... does vfx culling work in 8.31?
     
  7. hugangsheng

    hugangsheng

    Joined:
    Apr 13, 2021
    Posts:
    6
    Does the GPU instancing take effect when having many instances of the same VFX?
     
unityunity