Search Unity

Collider2D does not return Callback for ParticleSystem.TriggerModule

Discussion in '2D' started by kevwills, Jun 4, 2019.

  1. kevwills

    kevwills

    Joined:
    Feb 9, 2018
    Posts:
    5
    when using:
    int numInside = particleSystem.GetTriggerParticles(ParticleSystemTriggerEventType.Inside, insideList);

    with a Collider2D set as the trigger collider. The inside callback returns false (numInside==0).

    I've found a usable workaround (using a 3D collider, such as a box collider), but I think this issue is an oversight, and I want to point out that it feels inherently wrong to require a 3D collider for a 2D particle effect.
    ________________________________________________________________________
    I'm just going to outline my use case, to explain why this is important to me.

    I have a particle system that spawns bubbles as the character swims in water. The bubbles slowly rise, and can also be pushed around through the particle collision system. (the collision module lets me set it to 2D and reacts accordingly).

    I wanted the bubbles to "kill" when leaving the water, but could not use the simple on exit collider, because my water is comprised of layered colliders. This is done to create waves and tides dynamically.
    I turned to the ParticleSystem.TriggerModule as a simple solution. feed it all known water colliders, and then for each particle if they are inside at least one water collider, they survive, otherwise if they are outside all water colliders, they are decayed. This allows the bubbles to transition through water colliders seamlessly to the surface, no matter the current shape of the water.

    As it stands, I am creating a duplicate of the water colliders in 3D with the same bounds, but an additional z axis of depth, so that the trigger module's inside callback will return true. (this is extra complicated to recreate a shape resembling a 2D polygon collider) (I'm working on generating a mesh that duplicates the polygon colliders shape, instead of using boxes as guesstimates, but I'd rather not have to do this).

    _________________________________________________________________________

    Anyways, if it could please be integrated, that the trigger module of the particle system would accept 2D collider interactions, I would be very very happy.
    Thanks



    EDIT:
    If anyone wants a similar effect to those bubbles, I'll explain my best solution quickly.
    create a list of water colliders. Then on update, use GetParticles, to get the position of each active particle. use collider.OverlapPoint(vector2) with the position of the particle to determine if it's in water. If it's in any water, then spare that particle, otherwise kill it.

    I had tried to use the 3D mesh with the trigger module, but hit another roadblock, after extruding my polygonCollider2D into 3D meshes with some z width, I then found out that trigger colliders and rigidbodies for 3D shapes must be convex shapes. Instead of figuring out how to slice up a concave mesh into a bunch of concave meshes, I just gave up on that route (especially because trigger module seems to only accept 6 colliders max), and devised this other system relying on the original polygonCollider2D shapes.
     
    Last edited: Jun 5, 2019
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Hey, this does indeed sound incorrect.

    Could you report a bug so we can verify the problem and look at making a fix?

    Thanks!