GetPartBoundsInBox Not Detecting Overlaps in Same Collision Group

I’m testing this code (put in StarterCharacterScripts) to detect overlaps excluding parts inside the model:

Note: This code is just a demonstration of the issue

-- Test.lua
local RunService = game:GetService("RunService")

local testModel = Instance.new("Model")

local part = Instance.new("Part")
part.Anchored = true
part.CanCollide = true
part.CanTouch = true
part.Position = Vector3.new(0, 5, 0)
part.Size = Vector3.new(4, 4, 4)
part.CollisionGroup = "Test"

part.Parent = testModel
testModel.PrimaryPart = part
testModel.Parent = workspace

local overlapParams = OverlapParams.new()
overlapParams.FilterType = Enum.RaycastFilterType.Exclude
overlapParams.FilterDescendantsInstances = { testModel }

RunService.RenderStepped:Connect(function()
	local overlapParts = workspace:GetPartBoundsInBox(
		testModel:GetPivot(),
		testModel:GetExtentsSize() + Vector3.new(0.1, 0.1, 0.1),
		overlapParams
	)

	print("Overlaps:", #overlapParts)
	for _, p in ipairs(overlapParts) do
		print(" -", p:GetFullName())
	end
end)

I made a collision group called Test in Studio, set it to not collide with Default but collide with itself.

The problem is that the placed parts in the Test group that overlap with each other don’t show up in the print statements of the overlapParts table. This feels like a bug or a limitation since the code and collision settings look correct.

Is there any fix or way around this? I also want to keep CanCollide off no matter what (even though it was on in the test script above).

Parts are only detected if collisions with a certain collision group are enabled.

local overlapParams = OverlapParams.new()
overlapParams.FilterType = Enum.RaycastFilterType.Exclude
overlapParams.FilterDescendantsInstances = { testModel }
--Collision group is assumed to be "default"

it is explicitly because “test” can’t collide with Default, that those parts are being ignored. if you want to set certain parts to not show up in the query, then disable their CanCollide manually. alternatively, use BruteForceAllSlow.
here’s the documentation on this:

1 Like

ohh. I wasn’t aware that you can set the collision group of overlapParams. That makes much more sense then. I won’t but using BruteForceAllSlow due to performance issue but I will find another solution. Thanks

no problem.
BruteForce is a really last resort solution so any solution will find will be better. happy scripting!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.