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. Dismiss Notice

Question How to make collider mask with COMPOSITE OPERATION ?

Discussion in '2D' started by bewox, Aug 12, 2023.

  1. bewox

    bewox

    Joined:
    Apr 13, 2018
    Posts:
    18
    I recently upgraded to 2023.1.8 because there is new feature called composite operation.
    I expect this feature can be used as collider mask but unfortunately i still don't really understand to use it properly and can't make it work as i expected.

    I created two tilemaps with composite collider component and make the collider in both tilemap overlap each other. The idea is to remove the collider in the overlap area, so i use Flip (XOR) operation in the first tilemap.
    Here are my settings in both tilemap :

    cc1.jpg



    TILEMAP A :

    CC setting A.jpg



    TILEMAP B :

    CC setting B.jpg

    I actually did some trivial approach to use other combination of composite Operation in each tilemap but still no difference. I also tried to change the layer overrides settings trivially to see if there is a difference, but still nothing.
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    The CompositeOperation is used to control how compositing works for each composite. Two separate composites are just that, separate! In the example above, you're not compositing any colliders together. You've just got two TilemapCollider2D and they are the only thing being used by each composite.

    If you want to perform composite operations on two TilemapCollider2D then they need to be using the same CompositeCollider2D so place the composite on their parent GameObject and remove the ones on the Tilemap GameObject.

    Layer overrides are nothing to do with the composite as the docs state.

    You should try to understand how it works on a trivial example before moving forward. Get two colliders, add them to the composite using various composite operations.

    Take a look at my physics examples too:


     
    bewox likes this.
  3. bewox

    bewox

    Joined:
    Apr 13, 2018
    Posts:
    18
    Okay thanks melv, your second paragraph explains my misunderstanding.
     
    MelvMay likes this.
  4. rino3390

    rino3390

    Joined:
    Nov 15, 2018
    Posts:
    4
    How can I show the collider shape in color, like in your example? I downloaded it from your GitHub, and it works there, but I can't seem to display the shape in my own project. I can't find the code to make it show up.
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    Go to the Physics 2D Project Settings and select from the Gizmo Options: https://docs.unity3d.com/Manual/class-Physics2DManager.html (New options there are being able to fill collider interiors with color etc)

    You can configure the Physics 2D Colors themselves in Preferences: https://docs.unity3d.com/Manual/Preferences.html#2D

    In the future, please don't hijack threads, create your own so others can find the question more easily. :)
     
  6. rino3390

    rino3390

    Joined:
    Nov 15, 2018
    Posts:
    4
    Oh sorry, I will remember that.
    And thanks for the answer, I didn't know you could do it this way, that's really cool.
     
    MelvMay likes this.
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    You're most welcome.