I’m creating a raycast blacklist registry for my FPS game, and I decided instead of creating a giant table every time the player fires their gun, the script will have a table ready to go with the parts to ignore (transparent barriers, teammates, etc).

I ran into this though after doing some testing. [2] = void
, which isn’t the name of any part in Workspace, rather it’s a part that used to be in workspace but was now deleted. The registry saw it was deleted and removed it from the table, creating a void placeholder.
To be more specific, the registry script set Table[2]
(the index of the part that got deleted) to nil.
Question:
On a larger scale, should I be worried about hundreds or possibly thousands of void indexes? Does it affect performance/memory?
1 Like
Whether or not it causes performance issues, [x] = void
can be avoided by using table.remove
instead of setting it to nil.
I’m assuming since [x] = void
still existed, it’d use up an insanely small amount of memory, with hundreds or thousands of voids, I’m assuming it’d take up tiny but possibly somewhat noticeable amount of memory.
As a solution, just use table.remove
when working with arrays, don’t set to nil.
1 Like
There is a faster way using quick remove because in table remove it shifts the remaining indexes down by one to fill the gap which is unnecessary for this situation: here is the different solution:
However I believe using collision groups should be even faster as there is no tables to ignore just setting the collision group IDs and cancollides of the collision group though you would also have to manage that as well, I guess it’s up to you.
1 Like
I don’t think that’d word for raycasting, but I’ll look into the other solution, thank you.