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 have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Physics.OverlapBox doesn't detect collision with Character Controller

Discussion in 'Scripting' started by UnresolvedExternal, Nov 6, 2019.

  1. UnresolvedExternal

    UnresolvedExternal

    Joined:
    Apr 1, 2015
    Posts:
    16
    Hi! I'm using OverlapBox to detect if any object is occupying a certain space, it works great for objects that have a box collider, but it doesn't detect objects that have a Character Controller.

    Does anyone know why it doesn't detect Character Controller?

    Code (CSharp):
    1.             var numOverlaps = Physics.OverlapBoxNonAlloc(position, Vector3.one * 0.45f, overlaps, Quaternion.identity, ~(1 << LayerMask.NameToLayer("Terrain")), QueryTriggerInteraction.Ignore);
    2.  
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
  3. halivudestevez

    halivudestevez

    Joined:
    May 12, 2019
    Posts:
    13
    It should, as CharacterController contains a Collider - so it is expected by the developer.
    But the fact is above. So the solution: add a small collider to your character.