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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Physics.IgnoreCollision is asinine

Discussion in 'Physics' started by ArachnidAnimal, Aug 23, 2018.

  1. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    https://docs.unity3d.com/ScriptReference/Physics.IgnoreCollision.html
    2) You can only apply the ignore collision to colliders in active game objects.

    Can't Unity address this issue to find a way to remove this limitation?
    This has caused a lot of headaches.
    Furthermore, after enabling the gameobject or collider, we must wait one frame to elapse before calling the IgnoreCollision function. So the limitation is actually worse than what is stated in the manual.

    I shouldn't have to be concerned about whether the gameobject is active or inactive, or if the collider is enabled at the time of calling this function.
    Thanks.
     
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    How is it limiting you? I use it and have had no problems. It seems clearly documented, and I'm failing to see what the issue is. Of course you would have to wait for fixed update as it's a simulation step.

    Also the docs bug:
    upload_2018-8-23_22-41-42.png
     
    ArachnidAnimal likes this.
  3. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    So I don't see how the way that this works wouldn't pose an issue at some point:

    2. If any one of the game object or collider is disabled and re-enabled, the IgnoreCollision must be re-called. So it's not persistent throughout the life of the collider.
    The manual doesn't even mention that, we need to figure it out the hard way.
    Why can't Unity just handle this for us?

    3. Why are OnTriggerExit and OnTriggerEnter called when using IgnoreCollision?
    Now you have to add logic to OnTriggerExit or OnTriggerEnter to figure out if the reason it is being called is because you've used IgnoreCollision.

    It just doesn't seem right the way that this works
     
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Colliders are remade when the component (or the gameObject's active state changes). They aren't simply turned on and off as far as I know. This was probably a behaviour introduced to save memory and assist with the (old) Physx internal limitation for number of colliders.

    In 2018.3 it's likely there is no longer a limitation on number of colliders, however it will be up to Unity to decide if the present behaviour of recreating colliders is desirable. All that needs to change here is better documentation, as none of this is actually preventing you from doing anything.

    @yant could you confirm?
     
  5. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    577
    Wait a second. Hasn't the 'active' requirement been lifted a while ago? I recall rewriting that ignore code during some late 5.x stage.

    1) Calling Physics.IgnoreCollision doesn't result in OnTriggerXXX calls, as it was during early 5.x
    2) Do you really need to wait for one frame before calling Physics.IgnoreCollision after enabling a collider? That would be a bug I believe. What happens internally is we just put the parameters you pass to IgnoreCollision into appropriate arrays stored on the two colliders themselves (but not on the PhysX shape -- that's why it should be irrelevant whether it's active or not). I bet the doc is outdated.

    Finally, you need to understand that all the contact and trigger events are sent out during the simulation call (aka Physics.Simulate); for that reason, subscribing to a trigger event and changing the ignorance setting from there won't be applied until next frame. Hope that's fair enough.
     
    ArachnidAnimal and hippocoder like this.
  6. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    577
    Reported, will get fixed. Thanks for spotting.
     
    ArachnidAnimal and hippocoder like this.
  7. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    I re-tested what I have in 2017.1.1f and you're right, the 'active' requirement is no longer. Also, toggling off/on the gameobject or collider.enabled after calling IgnoreCollision(true) keeps the IgnoreCollision request now.
    As for the other issues, it's most likely user error on my part.

    I was continuing to go by what the manual says, not realizing that it changed some point in Unity 5.X

    Looks like just the docs need refreshing.