RemoveFromFilter RaycastFilter Method

So I’ve ran into an issue while raycasting in Parallel. A little while ago Roblox made it so you couldn’t change the FilterDescendantsInstances property of RaycastParameters in parallel and to help developers continue to raycast in parallel they created AddToFilter.

This method works really well for Blacklists. Hit a part? Don’t want to? AddToFilter() and Recast.

However there’s not currently a method for removing items from the filter, which would help a lot when using Whitelists or if I want a different raycast before synchronizing to hit the part I just added to the filter.

10 Likes

I asked the same question in the thread announcing the AddToFilter feature. Here was the response:

3 Likes

Have you got a particular code sample showing how you intend to use this?

3 Likes

I hate to argue with Roblox staff on this one, but unfortunately that viewpoint doesn’t seem to consider all the use-cases for parallel casting.

My use-case is raycasting for bullets mid-flight. I have a table of active bullets I’m checking in parallel. When it’s a bullet’s turn to perform a raycast check, I simply raycast, makes sense. I also have bullet penetration, so when a bullet hits someone, it logs the hit, and adds them to the ignorelist so a second cast can see who or what is behind them.

That’s great if one bullet was fired. But there’s usually multiple bullets in flight at any given time, and I can’t have all the bullets ignore that player, simply because one of the bullets already hit them.

For this use case is what you really want just :ClearFilter() so that you can reuse the same RaycastParams?

That would work well too, yes. Either one is good, but from a developer level a remove method seems more efficient than clearing and re-adding things.

(each bullet has some base descendants that are always ignored regardless of hits)

Ah, so in your use case you have a base set of stuff to ignore which all the bullets use and then per-bullet a few additional things it passed through?

Yes exactly.

Also if you have a more efficient suggestion for handling it that doesn’t require a feature request I’d love the input, I’ve been really racking my brain trying to get around this particular issue.

Yeah, that use case is a bit unfortunate. The fastest existing approach is probably to create N RaycastParams assigning FilterDescendantsInstances = sharedIgnore for N bullets first in the serial section and then add the additional entries in the parallel section.

I may give that a try in the interim until a better feature/solution arrives.

CollectionService cases would be a big one. Add to filter all objects with one tag, but without another.

1 Like