Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug onparticlecollision doesnt work with trigger colliders

Discussion in 'Editor & General Support' started by zeropointblack, Dec 14, 2022.

  1. zeropointblack

    zeropointblack

    Joined:
    Jun 8, 2020
    Posts:
    190
    is this a bug or what? this method call only works if the collider on the object is NOT is trigger. but thats really dumb and annoying, AND i WANT it to BE, "IS TRIGGER". so thats even more annoying.

    what can be done? is the only option to completely bypass this crap and just have another trigger collider enabled on the frames my item is "SHOOTING" out... ? and just try to have them line up with the particles being SHOT OUT?

    THANKS ALL.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,749
    Whoa... that's a lot of angst packed into one sentence.

    Are you perhaps looking for OnParticleTrigger()?

    You may wish to consider switching to a decaf brand. ;)
     
  3. zeropointblack

    zeropointblack

    Joined:
    Jun 8, 2020
    Posts:
    190
    LMAO. yeah i was excited last night when i SAW that on particle trigger, but it didnt work!!??

    now youre telling me to TRY it AGAIN? im willing. but if i come back here b*tching and moaning you wont like it. although i'll try to be as civil as possible.
     
  4. zeropointblack

    zeropointblack

    Joined:
    Jun 8, 2020
    Posts:
    190

    WELP, still doesnt work. i tried it on both the particle system and the other game object.

    is there some super special thing i should be doing? like that stupid TRIGGER section in the particle system that i have no idea what it means? or is it something else im missing?

    this method wont even let me pass an OTHER object into it, so whats the point anyway if you cant even check what tag it is. and yes i have it in world space and 3d and collision enabled and all the stuff like that. so like i said it works with oncollisionenter as long as is trigger is OFF.
     
  5. zeropointblack

    zeropointblack

    Joined:
    Jun 8, 2020
    Posts:
    190
    "OnParticleTrigger may not have any parameters"

    is that a joke? how else am i supposed to detect a tag then? why the f**K is this any different than a normal physics interaction within unity? jeeez. man what the hell is wrong with this stupid program? i know everything there is to know about collisions in unity, including trying to put rigidbodies on the triggers, and they still dont work. why does something clearly equipped with colliders and tags and scripts just for some reason have to do their own thing. come on, unity. get your act together.
     
  6. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,881
    Wow, chill out.

    The docs make it clear how the call back is to be used. Namely, on the same game object the particle system is on.

    Particles don't have any knowledge of the game object they came from. Looking at the docs it's been that way since Unity 5. Bit late to be complaining, sorry.
     
  7. zeropointblack

    zeropointblack

    Joined:
    Jun 8, 2020
    Posts:
    190

    you dont think i tried that or checked the docs? lol wut. u crazy?
     
  8. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,881
    Clearly I'm the crazy one because this:
    Code (CSharp):
    1. [ExecuteAlways]
    2. public class ParticleKiller : MonoBehaviour
    3. {
    4.     #region Inspector
    5.  
    6.     [SerializeField]
    7.     private new ParticleSystem particleSystem;
    8.  
    9.     #endregion
    10.  
    11.     #region Unity Callbacks
    12.  
    13.     private void OnParticleTrigger()
    14.     {
    15.         if (!particleSystem)
    16.         {
    17.             return;
    18.         }
    19.  
    20.         List<ParticleSystem.Particle> enteringParticles = new();
    21.  
    22.         int enterCount = particleSystem.GetTriggerParticles(ParticleSystemTriggerEventType.Enter, enteringParticles);
    23.  
    24.         for (int i = 0; i < enterCount; i++)
    25.         {
    26.             ParticleSystem.Particle p = enteringParticles[i];
    27.             p.remainingLifetime = 0;
    28.             enteringParticles[i] = p;
    29.         }
    30.  
    31.         particleSystem.SetTriggerParticles(ParticleSystemTriggerEventType.Enter, enteringParticles);
    32.     }
    33.  
    34.     #endregion
    35. }
    Worked totally fine for me. Video proof here: https://i.gyazo.com/d9717faaf46a088ddde2e9720b1a9831.mp4

    If it wasn't abundantly clear from the docs, the component that you want the trigger on has to be on the same game object as the particle system. You also need to assign the collider in the triggers module:
    upload_2022-12-15_20-47-30.png

    Hence why it doesn't have any parameters, because the object that is triggering the callback is the same game object emitting the particles. There's no need.

    In future instead of getting angry at a problem, try direct your energy at solving it.

    This was my first time using a particle system fyi.
     
  9. zeropointblack

    zeropointblack

    Joined:
    Jun 8, 2020
    Posts:
    190

    but why is it your first time? thats weird. i use them all the time.


    yes it was (somewhat) clear about the game object needing to be set in the triggers section (actually it didnt mention the need anywhere as i recall) (i did see it though in the particle system), but i dont know how to set that at runtime. if that is even possible. because i dont know ahead of time what particular prefab that will be just yet. you know?

    maybe a workaround for this horrendous bug would be to add and remove the items to the trigger list at runtime, since a simple detection wont work without it. seems strange. its a bug, trust me. because you can see it bugs me.
     
  10. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,881
    Once again it's all in the docs. You have access to the trigger module through the particle system: https://docs.unity3d.com/ScriptReference/ParticleSystem-trigger.html

    It's not a bug it's just how it works, and how it has worked since as far back as Unity 5.
     
    arkano22 likes this.
  11. zeropointblack

    zeropointblack

    Joined:
    Jun 8, 2020
    Posts:
    190
    that sounds like it might work, thanks. i'll keep that in mind if the need arises again. for now im just turning on a cone trigger game object when "shooting". probably more performant, but we'll see considering im already still using colliders and world space 3d calculations anyhow.

    next round i will try this again.