Accept subtables in RaycastParams.FilterDescendantsInstances

I want to ignore groups of parts when raycasting. Currently the solution is either to use CollisionGroups but they are limited to 32 per game so it’s very limited, or to use a single table that you have to manually manage, which is tedious and inefficient

If RaycastParams.FilterDescendantsInstances accepted subtables, it would make managing groups of parts much easier

local GlassParts = {workspace.Glass1, workspace.Glass2}
local Player1Hitbox = workspace.Character1.Hitbox:GetChildren()
local Player2Hitbox = workspace.Character2.Hitbox:GetChildren()

local Options = RaycastParams.new()
Options.FilterType = Enum.RaycastFilterType.Blacklist
Options.FilterDescendantsInstances = {GlassParts, {Player1Hitbox, Player2Hitbox}}
6 Likes

If you’re really worried about perf, using table.move should allow very fast construction of the aggregate table.

local ch1 = workspace.Character1.Hitbox:GetChildren()
local ch2 = workspace.Character2.Hitbox:GetChildren()
local ignore = table.create(#GlassParts + #ch1 + #ch2)
local ptr = 1
table.move(GlassParts, 1, #GlassParts, ptr, ignore)
ptr += #GlassParts
table.move(ch1, 1, #ch1, ptr, ignore)
ptr += #ch1
table.move(ch2, 1, #ch2, ptr, ignore)

You can implement a builder pattern that automates this. You can also use this in combination with table.clear to always re-use the same table to construct the ignore lists in too.

One reason not to do this is that the behavior would be very confusing with getting FilterDescendantsInstances:

Options.FilterDescendantsInstances = {GlassParts, {Player1Hitbox, Player2Hitbox}}
print(Options.FilterDescendantsInstances) --> ...is now a flat list?

I do not think it would be confusing at all. There would be 2 types allowed, table and Instance so you can just assume that all tables are groups of instances

Alternatively, making it possible to ignore parts with a CollectionService tag would make ignoring groups of parts easier

This will likely be implemented at some point. Adding support for collision groups to RaycastParams was just a first step in extending how you can filter things.

9 Likes

After thinking more about the original post, I agree that there shouldn’t actually be that much confusion.

I will look into doing this, good suggestion.

7 Likes