Search Unity

Physics.IgnoreCollision that does not reset trigger state?

Discussion in 'Physics' started by hoesterey, Jul 14, 2015.

  1. hoesterey

    hoesterey

    Joined:
    Mar 19, 2010
    Posts:
    659
    Hi,
    In the manual it says:
    Physics.Ignore collision is useful, say, for preventing projectiles from colliding with the object that fires them.

    I have a problem where I'm using Physics.IgnoreCollision to stop a projectile from hitting its own ship (I can't have every ships projectiles on separate layers as I can have many many factions all shooting at each other)


    Problem in the manual it also says: IgnoreCollision will reset the trigger state of affected colliders, so you might receive OnTriggerExit and OnTriggerEnter messages in response to calling this.

    So basically everytime a ship fires its guns it leave everyone's perception monitors disappear off radar for a frame (becoming un-selected) etc...

    Is there a way to dynamically ignore collision between two rigid-bodies specifically without resetting the trigger state?


    Thanks!
     
  2. hoesterey

    hoesterey

    Joined:
    Mar 19, 2010
    Posts:
    659
    Whats the process for reporting something that is called out in the manual as part of a feature but is functionally broke?

    Turns out when you ignore collision on a child it resets the trigger state on the entire hierarchy. So for example if a bullet ignores collision on a gun and a character holding the gun is standing on a pressure pad, the pressure pad would play its "you left me" and then the "you entered me" sound.

    I have a work-arounds but its dirty so our options are:
    -Remove all triggers in the game, replace with my own custom math.
    -Accept that entities will randomly enter/exit triggers.
    -Make anything that interacts with a trigger follow the game objects without being part of the hierarchy. (set position in code)

    For now I'm going to create a separate object set its position to the ships position every frame and have it only collide with monitor volumes.
     
    Last edited: Jul 16, 2015
  3. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    596
    Yes, that's because in PhysX 3 there is no longer any support for collision ignorance, so we had to add our own collision ignorance code in the Unity integration part. Currently, this code uses PxActor's resetFiltering function to re-filter contacts and that way inform PhysX on the changed ignorance pairs. Unfortunately, it seems to have a downside, where PhysX would remove an actor (with all it's shapes) from the broadphase, and add it back afterwards. I'll be looking into ways how we can improve it in the future.
     
  4. hoesterey

    hoesterey

    Joined:
    Mar 19, 2010
    Posts:
    659
    Thanks for looking into this!
     
  5. hoesterey

    hoesterey

    Joined:
    Mar 19, 2010
    Posts:
    659
    Yant,
    Can you post an update if you make progress on this? I'd hate to miss changes in the release notes. I'm currently cutting features from the product, making projectiles triggers as opposed to standard Colliders so I can ignore the damage in OnTrigger. The original intent was to have them be standard Colliders so they would bounce off level geo. Sadly though any work arounds that would allow me to use IgnoreCollision (to avoid having the rigid bodies effect the parents physics) are too buggy for my use case.

    Thanks again!
     
  6. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    596
    Yes, sure, there'll be something from the physics team on this once it gets resolved. In the meantime you can subscribe to my twitter @AnthonyYakovlev, where I mostly post on physics changes in Unity.
     
  7. hoesterey

    hoesterey

    Joined:
    Mar 19, 2010
    Posts:
    659
    Great thanks again!
     
  8. hurracharlie

    hurracharlie

    Joined:
    Dec 4, 2013
    Posts:
    1
    Hi guys,

    I currently have the same problem where i change Physics.IgnoreLayerCollision and this causes my OnTriggerExit and OnTriggerEnter to trigger when they shouldn't. I was wondering if anyone came up with a solution or work-around for this?
     
  9. hoesterey

    hoesterey

    Joined:
    Mar 19, 2010
    Posts:
    659
    No workaround, you need to not use the system sadly.

    I reworked my entire projectile system to user triggers so I could early out in code when the object collided with something it should be ignoring. I then manually apply the rigidbody type force though code when triggers collide, using ray tracing to ensure the correct collision point is calculated as objects with triggers will penetrate into each other. (OnCollision is called when rigid bodies touch but OnTriggerEnter can be called when the triggers are already well inside of each other, thus applying a force will be the wrong location, hence the raycast to determine earliest collision point)

    It's messy and took several days to refactor but without a solid delivery date on the fix we had to just not use the Unity physics system for projectile collisions.
     
  10. hoesterey

    hoesterey

    Joined:
    Mar 19, 2010
    Posts:
    659
    Heya Yant,
    I have not tested In a while. Did you have time to address this so Ignore no longer resets trigger states?
     
    LeonH likes this.
  11. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    596
    Unfortunately there's been no movement on this end so far. I have what you put there on the list and it's not forgotten but other priority stuff is still being worked on. Sorry for that.
     
    LeonH likes this.
  12. LeonH

    LeonH

    Joined:
    Oct 15, 2014
    Posts:
    92
    FWIW, we are also running into this issue and would be interested in improvements. Either that, or a lot more usable layers. :)
     
  13. duplexius

    duplexius

    Joined:
    Apr 24, 2015
    Posts:
    44
    I experience the same problem. For me it's not just a flaw, but a rather critical bug.
    I use Physics.IgnoreCollision to temporarily ignore collisions with the terrain so the player can fall through. I can't disable the entire terrain collider, as all other physical objects would fall through then as well.

    Can we escalate this somehow?
     
  14. hoesterey

    hoesterey

    Joined:
    Mar 19, 2010
    Posts:
    659
    Its a critical bug for me as well. I've rewritten my entire projectile system to work around this issue, but was forced to cut a lot of features out of the system that triggers just don't support.
     
  15. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    I've also just encountered this. While its not critical for me yet, there is no question that it will bite sooner or later. I'd like to keep updated on this too.
     
  16. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    596
    Hi guys,

    We've just crafted out a fix with Nvidia devs for this IgnoreCollision thingie. Just wanted to let you know It'll go live in Unity 5.5.

    Thank you!
    Anthony
     
    Martin_H likes this.
  17. Ceyl

    Ceyl

    Joined:
    Sep 9, 2015
    Posts:
    9
    Hi Yant,

    Is that fix available in the 5.5b yet ? I can not see it in the patch note.

    Cheers,
    Ceyl
     
  18. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    596
    I think it should be in thus far.
     
  19. silentslack

    silentslack

    Joined:
    Apr 5, 2013
    Posts:
    395
    Just ran into this myself, couldn't work out for the life of my why my OnTriggerExit was firing, now I know!

    Is there an official version number which has the fix?
     
  20. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    5.5 was just released but I don't see any 'fixed' note on this. Did it come with Physix 3.3?
     
  21. hoesterey

    hoesterey

    Joined:
    Mar 19, 2010
    Posts:
    659
    It did. I have not tested the released version but it was fixed in a previous beta!
     
  22. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    596
    I've just seen this fix was last verified with 5.5.0b3. Let me know if something got broken on the way. As for the release notes, seems something has probably been lost during the release notes update process. Sorry for that.
     
  23. Ceyl

    Ceyl

    Joined:
    Sep 9, 2015
    Posts:
    9
    Hi, maybe the ducmentation should be updated too with 5.5 if it's get fixed.

    "Note that IgnoreCollision will reset the trigger state of affected colliders, so you might receive OnTriggerExit and OnTriggerEnter messages in response to calling this."
     
  24. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    596
    Yeah, good suggestion.
     
  25. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    Yant,

    Can you clarify what got fixed? You just said you agreed with Ceyl's comment:

    "Hi, maybe the ducmentation should be updated too with 5.5 if it's get fixed.

    "Note that IgnoreCollision will reset the trigger state of affected colliders, so you might receive OnTriggerExit and OnTriggerEnter messages in response to calling this.""

    Agreeing with that comment implies that ignore collision still resets the trigger state of colliders??? I thought that was the thing that got fixed... :confused:
     
  26. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    On a separate but related subject, I'm now seeing something I haven't seen before prior to 5.5. When I dynamically add a rigidbody to a gameobject with a collider (the rigidbody is temporarily needed by a temporary fixedJoint.connectedBody), this appears to 'flicker' that collider's enabled state. I'm guessing its the collider's enabled state that 'flickers' because I have numerous other trigger colliders which have their OnTriggerExit() method called, followed immediately by their OnTriggerEnter() method which means they are detecting the disablement of the collider with the new rigidbody followed immediately by detecting its re-enablement.

    I'm not sure it is a bug, but it was definitely not there before. My workaround is straightforward - put the temp rigidbody on a temp gameobject as a child of the gameobject with the flickering collider. Walla, the collider no longer flickers.

    I'm not going to submit it as a bug, but I believe it is changed behaviour. Yant, are you aware of this?
     
  27. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    596
    To clarify: It was fixed, but somehow the documentation wasn't updated properly. You should be able to verify :)
     
  28. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    596
    I'm not aware of that. Please do report it for proper triage.
     
  29. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    I've submitted it as a bug.
     
  30. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,074
    So I have got additional question that I could not find in a documentation.

    What if I call IgnoreCollision with the same object multiple times. Will the internal list grow or is there a check for duplicates.

    What can I do to reset IgnoreCollision for particular Collider. Or remove particular pair from the list.

    Is Physics.GetIgnoreCollision including both Layer collision matrix and IgnoreCollision pairs, or just IgnoreCollision. Are other things like IsTrigger included.



    And one additional rant. Why Collider has something as useless as Tag property but don't have something so useful as Layer property.
     
  31. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    I removed my previous post here because I realised I do not intimately know the 3D physics side of things and speaking from 2D implementation isn't helping. :)

    I guess the answer is read the docs which show a true/false argument to specify if it's to be ignored or not. Maybe you're asking something more specific though I didn't pick up on?

    No, it's the opposite of the set call (IgnoreCollision) reading what you specified there. I mean, the hint is in the name of the method. The LayerCollisionMatrix doesn't have a Collider vs Collider setting so it's unrelated. I guess you're asking if this is a "CanTheseThingsEverCollideTakingEverythingIntoAccount(col1, col2)" sort of thing so no. Yes, triggers are part of it too just as you should expect. I mean you happily use the LayerCollisionMatrix that uses the word "collision" and that obviously includes triggers.

    It's personally why I loath the use of the term "collision" to mean "contact". If it were me, I would've named it "LayerContactMatrix" and "IgnoreContacts" etc but what is done is done. :)

    Confused. Collider doesn't implement either a Tag or Layer property. It's inherited from Component so nothing to do with physics but it's a shortcut to the GameObject and is not stored on the component. I guess nobody thought adding in a "Component.layer" was useful but again, not a physics thing.


    I'll add, Necro'ing posts like this isn't the best thing to do.
     
  32. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,074
    Lets just say that I have got a collider that had some IgnoreCollision applied and I don't know what are the other colliders.
    How can I reset it's ignore collisions to the starting state.
    GetIgnoreCollision unfortunately returns only state of two known colliders.


    I'm necroing because it is still semi-relevant question. I don't know why should we create new topic for this.
     
  33. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    We? You mean you. Your post is the very definition of a necro and hijacking but hey, you feel different so it therefore isn’t. ;) It doesn’t matter that the topic of this post is how ignoring collisions relate to physics callbacks. Your questions are completely unrelated. This isn’t THE thread for everything relating to IgnoreCollisions. This is why I mentioned it but still answered your questions first.

    So just another off-topic question. I don’t think there’s a call exposed to retrieve them all. I suspect for 3D they won’t survive a disable/enable but I’d need to check to be sure.
     
  34. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,074
    I can make another thread for this issue if you wish, not a problem. Your call.