Collision Detection Overview

There are three basic types of collision checks supported in Unreal, Raycast, Sweep and Overlap (defined in ESQType ). All three query types follow the basic flow of getting an Accelerator and a Spatial Visitor which iterates over the geometry in the Accelerator.

  • For Raycast and Sweep this is done by calling TSceneCastCommon and SceneTrace which in turn call LowLevelRaycast or LowLevelSweep
  • For Overlap queries this is done by calling GeomOverlapMultiImp then LowLevelOverlap

This geometry is stored in an AABB tree, which will get all leaf nodes in the query area and pass it to TSQVisitor::Visit visit. This Visitor will iterate over all FImplicitObject and query them

  • There are a few different types of FImplicitObject, basic objects like FCapsule and FBoxFloat3 , and complex objects TImplicitObjectTransformed and TImplicitObjectIntersection which contain other Objects and alter them in some way.

There is a different behavior for each query type

  • For Raycasts the Visitor will simply call FImplicitObject::Raycast
  • For Sweep, the Visitor will call Chaos::SweepQuery which runs a Raycast if the shape is effectively a point, or a GJK query if the shape is Convex. Otherwise it will recursively query complex shapes until it reaches a base shape that satisfies one of the above conditions
    The implementation in GJKRaycast2ImplSimd combines a few different algorithms, using GJK to detect overlap, then iterate over it with smaller / larger area to find contact points. It will fall back to EPA when GJK fails. For reference: GJK Overview Video and Text Explanation, EPA Explained, Finding Contact Points
  • For Overlap, the Visitor will call Chaos::OverlapQuery which works similar to Sweep, using GJK to detect overlap on convex shapes, and breaking down complex shapes until they are convex.