Search Unity

Filtering

Discussion in 'Physics' started by SpindizzyGames, Oct 17, 2017.

  1. SpindizzyGames

    SpindizzyGames

    Joined:
    Jun 29, 2017
    Posts:
    108
    Is it possible to filter collisions by ID without incurring a call to OnTrigger/Collision?

    Like say:

    only objects with ID 1 collide with each other, ignore all other ids
    only objects with ID 2 collide with each other, ignore al other ids

    I know people are handling this inside of OnTrigger/Collision - I'm wondering if it's possible without the overhead incurre by the function call
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,508
    SpindizzyGames likes this.
  3. SpindizzyGames

    SpindizzyGames

    Joined:
    Jun 29, 2017
    Posts:
    108
  4. SpindizzyGames

    SpindizzyGames

    Joined:
    Jun 29, 2017
    Posts:
    108
    two questions

    1) There is a limit of 24 user layers? what if I need more?

    2) can a layer be set or changed during run time through the scripting API?
     
  5. SpindizzyGames

    SpindizzyGames

    Joined:
    Jun 29, 2017
    Posts:
    108
    for 2) I meant - can I set or change an object's layer value during runtime through the scripting api?
     
  6. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,508
    1) Layers are limited by Unity, nothing we can do here. You may use some of the lower layers as well if they fit in your game's logic. For example, I've used the layer "Water" for "non-playable ground".

    2) Yes, layers may be changed anytime from scripting with immediate effect. GameObject.layer
     
    SpindizzyGames likes this.
  7. SpindizzyGames

    SpindizzyGames

    Joined:
    Jun 29, 2017
    Posts:
    108
    many thanks :)
     
    Edy likes this.