unity-physics-queries

Guide Unity physics query selection and NonAlloc buffer usage.

24|5|Updated Mar 10, 2026
One-click install
npx skills add https://github.com/Nice-Wolf-Studio/unity-claude-skills --skill unity-physics-queries
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unity-physics-queries
Source: https://github.com/Nice-Wolf-Studio/unity-claude-skills/tree/main/skills/unity-physics-queries
Command: npx skills add https://github.com/Nice-Wolf-Studio/unity-claude-skills --skill unity-physics-queries

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses common and often subtle bugs in Unity's physics query system (Raycast, SphereCast, OverlapSphere, etc.), preventing silent failures and ensuring accurate detection.

Core Features & Use Cases

  • Correct Query Selection: Guides users on choosing the right physics query for their needs (e.g., Raycast vs. OverlapSphere).
  • Allocation & Performance: Demonstrates efficient use of NonAlloc queries and buffer management to avoid garbage collection.
  • Edge Case Handling: Explains gotchas like trigger interaction defaults, hit ordering, and backface detection.
  • Use Case: Debugging why a ground check isn't working, or why a bullet seems to pass through an enemy.

Quick Start

Use the unity-physics-queries skill to understand the difference between SphereCast and OverlapSphere.

Frequently Asked Questions about unity-physics-queries

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does my Unity Raycast fail when the origin starts inside a collider?

Unity Raycast queries fail silently when the origin is inside a collider due to backface detection rules on non-convex MeshColliders. Correct physics query selection and configuring backface handling ensures accurate detection and prevents silent failures.

What's the best way to optimize Unity physics queries to avoid garbage collection?

To optimize Unity physics queries and avoid garbage collection, use NonAlloc variants like RaycastNonAlloc with pre-allocated buffers. This performance tier strategy prevents memory allocation during ground checks and frequent collision detection loops.

How do I choose between Unity SphereCast and OverlapSphere for collision detection?

Choosing between Unity SphereCast and OverlapSphere depends on motion: SphereCast sweeps a shape along a path to detect obstacles, while OverlapSphere checks a static volume. Correct query selection prevents subtle bugs like bullets passing through enemies.

Does Unity physics query hit ordering depend on LayerMask construction?

Unity physics query hit ordering is not guaranteed by distance unless specified, and incorrect LayerMask construction can filter out valid targets. Constructing LayerMasks carefully and verifying hit ordering ensures accurate trigger interaction and detection.

How do I fix Unity ground check physics queries not detecting trigger colliders?

Fix Unity ground check queries not detecting trigger colliders by adjusting the physics query interaction parameters. Unity's default trigger interaction settings often ignore trigger colliders, causing silent detection failures during Raycast or OverlapSphere checks.