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. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

[RELEASED] Better Physics Layers

Discussion in 'Assets and Asset Store' started by Clonkex, Nov 24, 2020.

  1. Clonkex

    Clonkex

    Joined:
    Jul 31, 2012
    Posts:
    31


    This is the support thread for Better Physics Layers. There's also a discord server, or you can email me directly. I'm brand new to publishing on the asset store so go nuts with questions and suggestions :)

    Description:

    Asset Store | Discord | Email | Demo
    ----------------------------------------------------------------------

    Better Physics Layers gives you fine-grained and easy-to-use control over which colliders can collide.

    ✅ Features:
    ----------------
    Up to 64 layers, totally separate from Unity's built-in layer system
    Separate physics layers from rendering layers
    Easy to use - Just specify which layer (or layers!) the object belongs to, without worrying about bitmasks
    Fine-grained control - Objects can belong to any combination of layers, and can collide with any combination of layers
    Mix and match - Any object without a PhysicsMask component will behave exactly like normal and won't be affected
    Fast - No measurable performance hit even with thousands of rigidbodies*
    Full source included, so you can inspect and modify to your heart's content

    ❔ Why?
    ----------------
    Normally, whether or not two colliders can collide depends on the GameObject's layer and the physics layer matrix. This is a problem for two main reasons:

    - There are only 32 layers, of which 8 are reserved, and these layers also affect rendering (among many other things!)
    - Objects can only belong to one layer at a time

    Better Physics Layers solves this by making good use of Unity's IgnoreCollision functions. This is extremely fast and doesn't hurt performance.

    I created this system because I needed it. While working on my portal system I discovered that it was extremely limiting not being able to have an object belong to more than one physics layer at once, and I quickly used up all 24 of Unity's customisable built-in layers.

    ❗ *Limitations:
    ----------------
    - Raycasts/spherecasts/etc. can't easily be filtered within the physics engine except by Unity's built-in layers, so there's an included function to filter the results of the cast instead.
    - There's a small performance cost to updating the collision ignores, simply due to sheer number of loops required. On my computer this is ~0.2ms in the editor with 100 objects, or ~3ms in the editor with 1000 objects. The cost is O(n^2). The collision ignores only need to be updated when changing layers or adding new objects, so in most cases this performance cost is negligible.
    - Currently only supports 3D physics, but I want to add 2D support in future.
     
    Last edited: Dec 3, 2020
  2. Clonkex

    Clonkex

    Joined:
    Jul 31, 2012
    Posts:
    31
    Reserved.
     
  3. Clonkex

    Clonkex

    Joined:
    Jul 31, 2012
    Posts:
    31
unityunity