Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Possible Bug - OnParticleTrigger() not called?

Discussion in '5.4 Beta' started by plmx, Jul 2, 2016.

  1. plmx

    plmx

    Joined:
    Sep 10, 2015
    Posts:
    308
    Hi,

    I am using the new Trigger module on a Particle System, and my OnParticleTrigger() method doesn't seem to be called.

    EDIT: I now understand how the trigger system is supposed to work. I was assuming that the OnParticleTrigger() method is invoked ON THE SELECTED COLLIDERS, not on the particle system itself. But it isn't - it is only called if the method is placed on the ParticleSystem.

    HOWEVER: The reason why I assumed it has to be on the collider game objects is that there is no parameter to OnParticleTrigger() and thus I have no idea which collider has actually been hit - or is there some other way to check this?

    Thanks!
     
    Last edited: Jul 2, 2016
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,281
    Hi,

    No, there is currently no way to know which collider has been hit.

    However, you're not the first person to ask about this, and we will look at adding it in the future :)

    The complication is that multiple particles could be triggering multiple different colliders, at the same time. So we will probably expose it as a function to retrieve the list of colliders, per particle.

    Or do you just need to know when a collider was hit, and don't care about which exact particles hit it?
     
  3. plmx

    plmx

    Joined:
    Sep 10, 2015
    Posts:
    308
    Cool, thanks!

    For my use case, it would indeed be (approximately) fine to just know which of the specified colliders was hit with at least one particle during the time interval covered (which, as I understand, is the meaning of OnParticleTrigger(), just for all colliders).

    Is this currently possible? (I had imagined I'd need a GameObject[] or Collider[] parameter to OnParticleTrigger() so I know which colliders have been hit in that time frame).

    That would be best! Another option would be to add a Collider or GameObject parameter for particleSystem.GetTriggerParticles() similar to particleSystem.GetCollisionEvents() so I can ask for collisions to a particular collider.

    Thanks!
     
    richardkettlewell likes this.
  4. Green-Sauce-Games

    Green-Sauce-Games

    Joined:
    Mar 27, 2014
    Posts:
    71
    I need to detect which particle collided, and with what Layer it collided, so I need to decide to kill this particle or not. Is this possible?
     
  5. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,281
    ParticleSystem.GetTriggerParticles will give you the list of particles that passed the trigger criteria.
    Unfortunately, I don't think you can find out the layer though.
     
  6. Green-Sauce-Games

    Green-Sauce-Games

    Joined:
    Mar 27, 2014
    Posts:
    71
    It will return me which object the particle have collided with? Am I able to kill the particle?
     
  7. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,281
    It won't return the object collided with. You can see the discussion about that feature request higher up this thread.

    You can kill a particle by setting its remainingLifetime property to 0, then assigning it back with SetTriggerParticles