Im making a lobby that will be vulnerable to parts spawning inside it, to counter this I plan to have the lobby scan for parts inside the area around it and delete any parts that do not belong there.
that being said I have two options that would work well:
region3
gettouchingparts()
both of these are good for detecting parts inside a specified area, but I plan to have the lobby constantly be on the lookout for foreign parts, which means I have to stick one of these in a while loop.
would one of these options be better performance wise? or would they be about the same?
Roblox doesn’t provide information as to the time complexity of their functions, thus this isn’t really possible to answer. Something I would recommend doing is to check whether or not parts are spawned in the lobby, and if they are then remove them.
If you are not intentionally letting players spawn parts, then you are setting up your game incorrectly.
Additionally, getting parts in a region3 is quite expensive, and is limited to a maximum of 20 parts, so you should keep that in mind.
no, having players spawn parts is intentional, lemme provide an example.
the game is for lack of a better explanation a sort of sandbox, there are tools that will do many different things. one for example will spawn an island and then the island will proceed to grow in size, creating landmasses, this will let the player build their own maps and initially its just the lobby that exists within the workspace.
now why is this relevant to my original question? well since the islands can expand, if a player were to grow an island near the lobby it would overlap. I could add a system that checks for space before spawning it but that’s not the way I want the game to be.
Checking whether a space is available before spawning/growing/expanding these islands is what you want to do. Otherwise, you cannot solve this problem in a decent way, outside of iterating through each placed island which is not ideal.
Also, I was just giving multiple possibilities to your question as it was rather vague.
well no, all I have to do is check for parts using GetTouchingParts() and remove any parts I don’t want inside it, Im just curious as to how performance heavy it would be to do this constantly over and over again.
Like I said, Roblox does not provide information on the time complexity of their custom functions/methods. This question is unanswerable.
That being said, if you want to use either Region3’s or GetTouchingParts, use the latter as Region3’s have an inherent limitation of 20 max parts. Edit: misinterpretation of api from memory, this is not true.
Using Region3s is probably the “lightest on preformance” , Region3 checks are calculated using simple aabb intersection tests, where as gettouchingparts is actually testing if two parts are intersecting (which is more expensive). Because it is aabb intersections, you would “loose some accuracy”, but i doubt that would be a big problem for your use case.
Once again, Roblox does not provide information as to the time complexity of their functions/methods. What this loosely means is that Roblox does not provide any information as to the performance of their functions/methods. Using tick() to calculate performance is not a good benchmark of time complexity and thus should not be used, unfortunately this is all we can use. That being said, because we can only use tick(), we cannot figure out the performance of any functions or methods created internally by Roblox.
Figure out which method works best for you, run a test using tick() if you want to, and use that one.
When i said probably i meant highly likely as aabb intersections are generally always cheaper, but here is what the FindPartsInRegion3 dev hub page says:
This method is a fairly quick and easy way to see if parts are in a general area. If a game needs to know if parts are exactly in an area, then BasePart:GetTouchingParts should be used. There is a higher cost to using BasePart:GetTouchingParts since a part is needed in the Workspace and the function takes more time to run.