Search Unity

How to properly destroy a VFXGraph GameObject?

Discussion in 'Visual Effect Graph' started by nra, Jan 13, 2021.

  1. nra

    nra

    Joined:
    Dec 16, 2013
    Posts:
    8
    So I've been playing around with VFXGraph and got some great results, only to find there is no good way (through reading API spec and Googling) to know when to destroy an instantiated VFXGraph GameObject.

    All the forums come up with are dead(no answer) posts like https://forum.unity.com/threads/is-...-graph-finished-emittion.872458/#post-5740168 and https://forum.unity.com/threads/des...fect-has-played-sounds-simple-but-how.971970/


    I understand by the system being on the GPU there is a delay, but surely everyone loving the system must have a way to destroy objects that is more than a Destroy(X, _from the hip number of seconds that should be enough) ?
     
  2. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hi @nra ,

    You can check the number of alive particles like this:
    Code (CSharp):
    1. vfx = GetComponent<VisualEffect>();
    2. Debug.Log(vfx.aliveParticleCount);
    There is some latency, but you can use it to check after you've started spawning when it drops to zero so you can destroy/recycle your VFX game object. You are correct though that there isn't a callback or any convenient "vfx.isPlaying" method at the moment (it's on the roadmap.)

    Hope this helps!
     
    nra likes this.
  3. nra

    nra

    Joined:
    Dec 16, 2013
    Posts:
    8
    Cool to get a "confirm" from someone from Unity.
    Was using the `aliveParticleCount` but in a real S***ty way (set a bool to True once `aliveParticleCount` is above 0 then destroy on 0) in my "dev-environment" and was wondering if there was a something I was missing (I started initially looking into sending an event in the graph).

    Thanks again Vlad!
     
    VladVNeykov likes this.
  4. bwaite87

    bwaite87

    Joined:
    Nov 23, 2017
    Posts:
    18
    is there any update to this? Would love a .isplaying bool to be added
     
    Orion-M42 and Hexane like this.