fix(physics): unify scene query filtering to use collisionLayer#2964
Conversation
…ery filtering Scene queries (raycast, sweep, overlap) were using entity.layer for filtering, while physics collision used collider.collisionLayer. This inconsistency meant users had to manage two separate layer systems. Unified to use collisionLayer for all physics filtering.
Update CharacterController raycast test to set collisionLayer on the collider rather than entity.layer, matching the unified filtering logic.
WalkthroughThe physics scene's pre-filter logic for raycasts and sweeps now accesses collision layers directly via Changes
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev/2.0 #2964 +/- ##
===========================================
- Coverage 77.54% 77.32% -0.22%
===========================================
Files 900 900
Lines 98724 98724
Branches 9802 9809 +7
===========================================
- Hits 76560 76343 -217
- Misses 21998 22214 +216
- Partials 166 167 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
GuoLei1990
left a comment
There was a problem hiding this comment.
总结
将场景查询(raycast/sweep/overlap)的过滤从 entity.layer 统一到 collider.collisionLayer,方向正确,与 Unity 的设计一致——Unity 用一套 layer 统一管理所有物理过滤。改动精准,只改了一行核心逻辑 + 测试对齐,没有多余改动。
问题
无。
改动范围小且方向清晰,代码干净。
背景
之前物理系统存在两套 layer 过滤机制:
entity.layer过滤collider.collisionLayer过滤这对用户来说很不直观——同样是物理相关的操作,需要分别设置两个不同的 layer 才能得到预期结果。
从用户角度看问题
射线检测本质上也是一种物理查询,用户的直觉是:我在 collider 上设了
collisionLayer,那所有物理相关的过滤(碰撞、射线、扫描、重叠检测)都应该走这个 layer。不应该还要额外去设entity.layer才能让射线检测生效。统一后的心智模型很简单:
collisionLayer→ 管所有物理相关的事entity.layer→ 管渲染剔除等非物理的事职责清晰,互不干扰。这也和 Unity 的设计思路一致——用一套 layer 统一管理所有物理过滤。
改动
PhysicsScene._createPreFilter中将shape.collider.entity.layer & mask改为shape.collider.collisionLayer & maskcollisionLayer替代entity.layer测试计划
collisionLayer正常工作