We are adding new WorldRoot (Workspace) APIs for performing spatial queries on BaseParts. It’s never been easier to figure out what Parts are within a given box, radius, or other Part!
Here are three new functions that can be used:
Objects WorldRoot:GetPartBoundsInBox(CFrame cframe, Vector3 size, OverlapParams overlapParams)
- Returns a table of all BaseParts whose bounding boxes overlap the given box at
cframeis for the center of the box, and orientation is taken into account.
Objects WorldRoot:GetPartBoundsInRadius(Vector3 position, float radius, OverlapParams overlapParams)
- Returns a table of all BaseParts whose bounding boxes overlap the given sphere at
Objects WorldRoot:GetPartsInPart(PartInstance part, OverlapParams overlapParams)
- Returns a table of all BaseParts who overlap the given
part. The given
partmust be present in the same WorldModel (workspace) as the parts you want to query. CanCollide/CanTouch on the given
partare not considered, just the Part’s geometry.
A key thing to note with these is the Box and Radius overlap queries will only check against Part bounding boxes (the blue box shown when you select a Part). This makes them pretty fast to use. The Part overlap query will do a full geometry collision check, so it is more accurate. Later on we may add more overlap queries with new geometry, and of varying levels of detail.
What is this extra “OverlapParams” parameter? It’s a new parameter object with a set of properties used to define rules for the overlap query to follow. It works like
RaycastParams, and even shares many of the same properties.
Objects FilterDescendantsInstances- An array of objects whose descendants will be used in filtering.
RaycastFilterType FilterType- RaycastFilterType.Whitelist or RaycastFilterType.Blacklist. Determines how the FilterDescendantInstances is used.
Blacklistwill skip the
Whitelistwill exclusively include them.
int MaxParts = 0- The maximum amount of parts to be returned by the query. The process simply early outs once this is met. (0 is infinite)
string CollisionGroup = "Default"- The collision group the region check is performed on. Parts set to not collide with this group will be ignored.
With these new functions, the following “Region3” based functions are all deprecated, and should not be used in new work:
WorldRoot:GetPartsInPart can be used in place of
Part:GetTouchingParts, and is a better choice most of the time. However, a few niche cases prevent us from deprecating
GetTouchingParts at this time.