Table.Insert() doesn't work with RaycastParams.FilterDescendantsInstances?

Could this be moved to engine bugs please as I cannot post there?

I was attempting to add a large amount of specific objects into RaycastParams.FilterDescendantsInstances at runtime using table.insert(), but it doesn’t work, nor does it throw an error. I did find a work around though.

I don’t know if this is an intentional aspect, I apologize for posting this if it is intentional though.

If you use table.unpack after inserting the table into RaycastParams it appears to work fine. This is the current method I am using as a work around.

This doesnt work

local Part = Instance.new("Part")
Part.Parent = workspace

local RaycastParameters = RaycastParams.new()
RaycastParameters.FilterDescendantsInstances = {}

table.insert(RaycastParameters.FilterDescendantsInstances, Part)

This does work

local Part = Instance.new("Part")
Part.Parent = workspace

local RaycastParameters = RaycastParams.new()
RaycastParameters.FilterDescendantsInstances = {}

local TempTable = {}
table.insert(TempTable, Part)

RaycastParameters.FilterDescendantsInstances = {table.unpack(TempTable)}

The examples shown above are not the code I am using, they just specifically show that table.insert doesn’t work. I am aware I could just add “Part” to the table, but that is not the point of the examples. Thanks and have a good one :slight_smile: !

2 Likes

FilterDescendantsInstances will always return a deep copy of the table, so you will have to do it the way you are doing it in the second example.

What is a “deep copy”? I have never heard of this.

local RaycastParameters = RaycastParams.new()
RaycastParameters.FilterDescendantsInstances = {}
print(RaycastParameters.FilterDescendantsInstances == RaycastParameters.FilterDescendantsInstances)
-- prints false

Since a.b invokes __index, it will return a new table with the same contents.

1 Like