FilterDescendantsInstances, some help please

Hi! Just having a bit of problems understanding how FilterDescendantsInstances is used.

Docos say;
array RaycastParams.FilterDescendantsInstances
An array of objects whose descendants will be used in filtering raycasting candidates

This is my code;

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Whitelist
-- 1. FAILS raycastParams.FilterDescendantsInstances = {workspace.fog1:GetChildren(), workspace.structures:GetChildren()}
-- 2. FAILS raycastParams.FilterDescendantsInstances = {workspace.fog1:GetChildren()}
-- 3. WORKS raycastParams.FilterDescendantsInstances = workspace.fog1:GetChildren()
-- 4. WORKS raycastParams.FilterDescendantsInstances = workspace.structures:GetChildren()

Lines 3 and 4 work as expected. I’ve omitted the raycast itself for brevity.

So a few questions;
a) why can’t I just use workspace.fog1 (it fails)? I have to pass workspace.fog1:GetChildren()(it works!). The documents say the “descendants” will be used, and the property itself is an array.

b) if I set a single object, eg lines 3 and 4, it works. If I wrap them in an array {}, it fails. Why? This causes the next problem…

c) How do I include the descendants of both folders (workspace.fog1 and workspace.structures) in my whitelist?

thanks

1 Like

The reason your no. 1 and 2 fails, is because that result in ‘an array containing two (or one) items (that are arrays)’. I.e.:

{ { childA1, childA2, childA3 } , { childB1, childB2, childB3 } }

Since :GetChildren() returns an array, that is why your no. 3 and 4 works.

So to get your no. 1 to work, you would need to combine what those two :GetChildren() returns into a single array:

{ childA1, childA2, childA3, childB1, childB2, childB3 }

Something like:

local arry = workspace.fog1:GetChildren()
for _, p in ipairs(workspace.structures:GetChildren()) do
  table.insert(arry, p)
end

Or perhaps using table.move:

local arry1 = workspace.fog1:GetChildren()
local arry2 = workspace.structures:GetChildren()
local arry = table.move(arry2, 1, #arry2, #arry1 + 1, arry1)
3 Likes

It says here for RaycastParams FilterDescendantsInstances:
An array of objects whose descendants will be used in filtering raycasting candidates.
So its an array
local array = { }

Of Objects
local array = {game.Players.LocalPlayer.Character, game.Workspace.Folder}

And the decendants of the object in the array will be used in filtering.
This worked for me and should work for you too!

1 Like