Search Unity

Ignore between a collider and a layer

Discussion in 'Physics' started by Maeslezo, Mar 6, 2017.

  1. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    331
    GregoryFenn likes this.
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,492
    That's what IgnoreLayerCollision does. It's not "between layers" but more, a collider on one layer won't collide with a collider on the other layer.
     
  3. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    331
    Hello @MelvMay,

    I think I did not explain myself,

    I want that a specific particular collider does not collide with an entire layer.

    Imagine Layer A and Layer B.

    I want that all the colliders of A collides with B.

    But, I want that a specific collider of A, because of an event, stop colliding with all the layer B, but the other colliders of layer A still collides with Layer B

    Code (CSharp):
    1. private void OnTriggerEnter(Collider c)
    2. {
    3.    if (Something(c))
    4.   {
    5.      Physics.IgnoreCollisionColliderAndLayer(c, LayerB)
    6.   }
    7. }
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,492
    Unfortunately we don't support that yet but it would be possible to implement it and we already do have this on a planning board card, just at a low priority. I know this doesn't help.

    The only other way to do this is to use a Kinematic body-type with full kinematic contacts set. That way you explicitly control what happens but you also obviously need to control the collision reactions too.
     
  5. cwbeta

    cwbeta

    Joined:
    Jan 12, 2017
    Posts:
    32
    I suggest that you can create a Layer C which do not collide with Layer B.
    When you want to ignore the collision between a specific collider and Layer B, you can temporarily switch its layer to Layer C.
     
  6. GregoryFenn

    GregoryFenn

    Joined:
    Feb 13, 2018
    Posts:
    43
    This feature would be useful. I know we can create a new layer L1 for a specific object and then say that L1 objects should be masked from L2 objects, but this involves defining a new layer just for the specific object, which is not hard but it's hugely wasteful when we have a mere 30 or so layers to play with. It's possible that a game would have more than 32 kinds of objects, so having a way to tell specific object's to ignore a certain layer without having to make a special layer for it would be very very useful.
     
  7. aegis123321

    aegis123321

    Joined:
    Jul 5, 2015
    Posts:
    71
    Any updates? I really need this feature in Physics2D, too.
     
  8. Crazycarpet

    Crazycarpet

    Joined:
    Dec 5, 2015
    Posts:
    47
    I hope this gets added as well, my world destruction system could get a lot simpler with it. Right now I just change the destroyed object's layer when it gets destroyed... but this causes issues if you want to destroy an object already in a layer without changing it's layer.
     
    Nintendo-Silence likes this.
  9. ayhanavci

    ayhanavci

    Joined:
    Dec 3, 2019
    Posts:
    4
    Bump. Any news on that? This is causing some tasteless implementations. I'd like an object's collider (and only that one) to decide which layers to ignore / unignore.
     
    raymondy1 and Jar_Coding like this.
  10. entirelydoomed

    entirelydoomed

    Joined:
    Mar 26, 2021
    Posts:
    67
    I really need that feature rn. Trying to implement some portal system and i need to disable all collisions for the object passing through portal so that it can get through it even if there's a wall behind. Ignoring collision for the whole layer would lead to other objects of the same layer just falling through the ground while this object traverses the portal. Dunno if i'll find a suitable workaround for that...
     
    raymondy1, Grafos and ayhanavci like this.
  11. PixelDough

    PixelDough

    Joined:
    Apr 27, 2018
    Posts:
    56
    It's somewhat impressive that this hasn't been added yet. It seems like a somewhat simple feature to add. Would be great to finally get this in!
     
    raymondy1, Grafos and ayhanavci like this.
  12. antiNT

    antiNT

    Joined:
    Apr 9, 2015
    Posts:
    5
    Would be useful for sure, please keep us updated.
     
  13. ayhanavci

    ayhanavci

    Joined:
    Dec 3, 2019
    Posts:
    4
    Hi MelvMay, This has been 4 years since you posted this. Has it still not come up? Personally I can't comprehend how this is a low priority issue tbh. An object should be able to choose which layers it can collide with. To me at least, if you build a rather big 2d game, it is going to cause a huge headache and spaghetti code without this, because:
    a) You globally make layers ignore each other. If you do this, you can't customise your objects and you will need maybe hundreds of layers. or
    b) Every object in a scene has to keep a reference to every other object it wants to ignore/allow collisions which is one of the most horrible anti-patterns in software design.
    c) You happily let everything collide with everything else and decide your action on trigger / collide events. Which has its own issues with bloated code, objects with rigidbody and again, bad design, possibly performance.
    I'm wasting considerable amount of time in my game just because I am forced to work around this.

    Some sort of a function like Collider.Ignorelayers(Layermask) or Gameobject.Ignorelayers(Layermask) should be enough.

    I'd love to hear from you. Thanks.
     
    Last edited: Oct 19, 2021
  14. DrMox

    DrMox

    Joined:
    Dec 30, 2013
    Posts:
    5
    Hola :)

    I second the guys above me, this would be quite useful, especially since layers are not only used for physics objects and are of a limited quantity.
     
    ayhanavci and Crazycarpet like this.
  15. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    345

    This is really needed asap, since currently unity mixes rendering layers and physics layers, wich makes it terrible in order to work properly with these, if unity were using the physics layers systems as DOTS physics cathegories this would be awesome

    Maybe you could ad this layering system and call it Physics layers 2.0, so people can switch and decide which one to use in their project, so you would be able to chose the "Belongs to / Collides with" by each collider, offerinh an incredible flexibility and finally decoupling it from rendering...
     
  16. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,492
  17. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    345
  18. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,492
    The 2D physics and 3D physics teams are seperate.

    I know work on 3D physics here was being done, let me check on its progress with respect to 2022.2.
     
    Maeslezo and Extrys like this.
  19. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    345
    Nice, let us know if its confirmed please!
     
  20. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,492
    I can see the PR but I don't think it's landed in the 2022.2 alpha yet but it was just confirmed that it should land in 2022.2 (in Review/QV but not landed yet). It has the same include/exclude properties on Rigidbody and ArticulationBody too.

    I cannot link to any API docs until it lands though as they are published shortly after that but they work in the same way as the 2D equivalent.
     
    adamgolden and Extrys like this.
  21. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    345
    Nice! good to know thanks a lot!
     
  22. TextusGames

    TextusGames

    Joined:
    Dec 8, 2016
    Posts:
    429
  23. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    331
    TextusGames likes this.
  24. NestorVG

    NestorVG

    Joined:
    Feb 12, 2019
    Posts:
    35

    Is there any chance this will be added to the 2021.3 LTS???
     
  25. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,492
    No. Features are never backported in Unity, only bug fixes get backported.
     
    TextusGames likes this.