Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Can't find any way to kill a particle with an event.

Discussion in 'Visual Effect Graph' started by Guema, Jul 25, 2022.

  1. Guema

    Guema

    Joined:
    Jun 21, 2015
    Posts:
    7
    Hey, i'm posting this because i can't find any any answer to my problem.

    I want to kill a specific particle, not just stopping a system, but kill a particular particle.

    Little background of the why here, i'm making a magic projectile VFX and one of its element is a main particle sprite that i spawn in a single burst of one. I disabled its aging, because i want to kill it when the projectile's gameobject hit something its script then send the OnDeath event to the VFX Component. The OnDeath event stops all the nodes that play normally, and triggers a Missile death quick flash/explosion. But OnDeath as no effet on the main particle, i assume OnStop stops the emitting.

    I tryied to expose a bool or float to manually entering, kind of work but i don't want to expose it in inspector. It's a runtime scoped value that shouldn't be changed.

    What i really want is some kind of C# event i can connect to set age or set alive node, but i didn't find any of this. The only events are Gpu event, but it's inapplicable here, because GPU event will not react to my script. The normal only link to particle system, and can't be used to modify existing particle properties...

    What shoukd i do '? Possible?
     
  2. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    337
  3. Guema

    Guema

    Joined:
    Jun 21, 2015
    Posts:
    7
    TYVM, could be exactly what i'm trying to accomplish.
    Will check out your thread and update
     
  4. Guema

    Guema

    Joined:
    Jun 21, 2015
    Posts:
    7
    After investigating, Your problem seems not exactly what i'm encountering,
    this problem is so still active, and i'm still not able to find a solution.

    I'm really surprised that i'm not able to find an answer on the net.

    The only different setup i have from the "default tutorial case" is that i'm not spawning hundreds of particles on the head, but only one
    In the tutorial case, you just stop the spawning, and particles will die by themself

    Spawning lots of particle which kill themself fast is good when you need to render things living and dynamic like fire, but i don't need this for this particular one, it is a "pure arcane magic" projectile, i want it to look very stable and ordered.

    I could maybe set its lifetime for 0.1 and respawn it every time, but it would be weird that the solution to show a single and very static sprite would be to respawn it billions of time where 1 should be enough...

    Also i can't kill the whole VFX, because, i want that the VFX plays it's "Death particle effect" part before dying effectively as a game object or being disabled.

    Currently, the particle initiate as OnStart, then when the projectile go is hitting something, i send event "OnDeath, which disable most of effects and play another set of effects on the graph.

    Then i wait till the particle amount is 0 to disable it. I know it's a slow method, but it's not a problem, my game is Event Driven. If it already triggered it's death Event, it will do nothing else... Except showing particles i can't manage to kill because nothing seems to be able to allow it.

    So do someone have a clue or a something for what i'm trying to do ?
     
    Last edited: Jul 31, 2022
  5. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,296
    Currently if you want to kill particle or do something event like you must do it trough vfx graph properties.
    For example let say there is projectile represented by single particle. This is bad idea, unless you have single graph for all particles in your game (why would you make whole vfx for single particle?).
    Now you want to kill certain particle. If your effect is divided into multiple systems then most likely you just want to kill all particles of that system. You can create bool property (default: false), then create condition inside graph something like:
    Code (CSharp):
    1. if (killParticles == true)
    2. {
    3.     someParticle.alive = false;
    4. }
    or even directly assign that property to alive, so it will be killed in this update. This logic would be run in Update context and you would set your flag to true/false for single frame to trigger this event once.
    You can create more complicated logic to kill particles, for example check their attribute to know if it should be killed.
    The only other way to control them is buffer, but there is the same idea, you just update particles according to buffer data.
     
    Guema likes this.
  6. Guema

    Guema

    Joined:
    Jun 21, 2015
    Posts:
    7
    Thanks for your answer and help,

    Yeah, i have multiple systems in my whole graph.
    upload_2022-8-1_0-31-35.png

    Only one is giving me problems (the one at the very left). My problem with properties is that they are exposed in inspector.

    I'm not sure about what you refer trough "Property" the properties i know are the one you can define and expose in Blackboard.

    My problem with properties is that i don't want this particular value be editable in inspector (or at least not directly like this) by an eventual GD or most likely the future me who forgot what this value do. This is not like a color or a gradient, i want this value to be C# managed only.

    Is their so a way to expose it only to code or to access non exposed values from C# ?
     

    Attached Files:

  7. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,296
    Sadly I can't see too much in this picture.

    Yes, I mean these properties.
    Well, I understand your problem, but it's not like you have much choice (I guess there is no other way right now), plus I don't think that's a huge problem - you can add tooltip to this property, and on top of this you can create separate section/category in the blackboard and name it something like "CONTROLLED BY SCRIPT - DO NOT TOUCH OR YOU DIE" :D
     
  8. Guema

    Guema

    Joined:
    Jun 21, 2015
    Posts:
    7
    Ok, TYVM for your help and infos.

    It's not exactly ideal setup, but it seems i don't have much choice has you said.

    I was actually aware this take would work but seemed like not a good practice to me.

    Like making all your scripts fields public in C#...

    This is quite surprising that there is absolutely no way to hide it in inspector while exposing it for code...

    Thank you Guys for your help.