Skip to content

Add collision layers with a per-project collision matrix - #857

Open
Gopmyc wants to merge 4 commits into
Overload-Technologies:mainfrom
Gopmyc:856
Open

Gopmyc wants to merge 4 commits into
Overload-Technologies:mainfrom
Gopmyc:856

Conversation

@Gopmyc

@Gopmyc Gopmyc commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Description

A project now holds up to 32 named collision layers and a symmetric matrix deciding which ones collide. Every physical object carries a layer, applied as the Bullet broadphase group and mask, so nothing filters collisions today beyond making a body a trigger or disabling it. Layers are edited in Project Settings, picked in the inspector, and both the layer and the matrix are readable and writable from Lua.

Related Issue(s)

Fixes #856

Review Guidance

  • Layers are fixed slots, as in Unity : naming a free slot creates a layer, removing one frees its slot, and indices never shift. Scenes store the index in collision_layer, so renaming is free. A freed slot is reused by the next created layer, and objects left on it join it.
  • 32 is the width of a Bullet collision mask, not an arbitrary cap.
  • Layer and matrix changes are applied in PreUpdate, never synchronously. The contact callback reaches Lua inside stepSimulation, so removing a body from the world there would free the collision algorithm in use. Re-entering the world is also what drops the cached broadphase pair, whose manifold would otherwise keep pushing filtered bodies apart.
  • Raycasts force AllFilter, so they keep hitting every layer.
  • Static bodies no longer get Bullet's implicit StaticFilter exclusion, so static pairs now reach the broadphase and are rejected by needsCollision, both bodies being inactive. More pairs, same behaviour.
  • New project keys collision_layer_<n> and collision_mask_<n>, left out of IsProjectSettingsIntegrityVerified on purpose : that check wipes every setting when a key is missing. Existing projects keep their settings and start with the Default layer alone, and scenes without collision_layer load on it.
  • Out of scope : ignoring collisions between two specific objects, and a layer mask parameter on Physics.Raycast.

Screenshots/GIFs

N/A

AI Usage Disclosure

Refactored code

Checklist

  • My code follows the project's code style guidelines
  • When applicable, I have commented my code, particularly in hard-to-understand areas
  • When applicable, I have updated the documentation accordingly
  • My changes don't generate new warnings or errors
  • I have reviewed and take responsibility for all code in this PR (including any AI-assisted contributions)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Let scripts disable collisions between two actors

1 participant