PlayerModule.CameraModule.ZoomController.Popper queryPoint, Raycast piercing optimization issue, stacked Parts doing a recursive amount of lag spikes

Description

Once, there was an issue with Raycasts. At first I thought it was the Raycasts themselves.
But there were issues, and one of the issues is caused by Roblox’s default CameraModule.

 

These lag spikes are from the default CameraModule script that comes with Roblox.

 

The causing function seems to be queryPoint from PlayerModule.CameraModule.ZoomController.Popper. And these lag spikes happen on every hardware.

 

So, there’s a community attempt and Roblox’s attempt.

Both have in common that they try to “pierce” through things, but there seems to be something wrong with parts that are stacked into each other, and or parts that are slightly positioned differently.

Whenever there are stacked parts, the script handles something wrong, and it seems to have issues piercing through. The piercing gets stuck, and it “loops” through these forever. And because of it recursively triggering this function everytime, it causes these lag spikes.

 

Re-production Steps

  • Open the re-production place file from the Private Message.

  • Delete PlayerModuleDisabled or PlayerModule if there is any, as that is my override, that I kept there.

  • Start the game with F5 or similar.

  • Go to this thing

  • Make the camera collide on these parts, by holding Right Click and moving it around.

 

Expected Result

No performance impact, but the camera stops at where it should stop. :thinking:

Actual Result

A lot of spikes in the MicroProfiler.

 


A private message is associated with this bug report

Please reach out to the Nexus VR developer, it’s not part of the Roblox Engine.

I think I phrased something wrong. The above is a comparison I made, in certain games that use these modules that cause performance issues. There being two, one is a community made thing. And the other one is from Roblox.

Roblox’s CameraModule. The path is PlayerModule.CameraModule.ZoomController.Popper

Both of these, but the important one is Roblox’s.
Is that there’s an issue with how they do piercing with raycasts, including Roblox’s CameraModule (from Roblox).

The reason I mentioned NexusVR, is because maybe it’s a useful insight to fix the issue, or create a new feature that could be helpful for everyone? :person_shrugging:

But the entire bug is about Roblox’s CameraModule. I just wanted to mention that maybe there may be games that do similar, but also have the same issue.

Sorry, if it was confusing. I edited the post to remove all confusing parts, and then re-opened the ticket.

To clarify PlayerModule.CameraModule.ZoomController.Popper is using our raycasts to check for collision. E.g. when you walk into a building, this is what pulls the camera in to prevent your view from clipping with the geometry.

And these lag spikes happen on every hardware.

The cost of the function above is directly related to how complex the geometry is.
So e.g. an object with more polygons would take longer to raycast against. When you say “there’s an issue with how they do piercing with raycasts”, is that what you mean?

Whenever there are stacked parts, the script handles something wrong, and it seems to have issues piercing through. The piercing gets stuck, and it “loops” through these forever.

If that’s the case, then this would be a bug in the raycast or physics system, not the camera per se.

It’s in queryPoint.

I haven’t analyzed the script. But I lowered a limit, and the spikes reduced, so it’s something in the script?

Like, I guess I can go analyze it again.

The piercing is something custom by the script. And I think the script is getting itself stuck in a loop, because the stacked parts, like 2 stacked parts or more. Maybe the Raycast gets casted from the same location again.

But there are stacked parts at the same location. So it will just repeat this forever. Stacked parts in terms they’re into each other, similar to z-fighting, where they are exactly overlapping over each other.

Summary

I asked the engineers working on this and they say it’s not a loop, but just expensive to pierce through multiple objects. E.g. if you have semi-transparent parts or the trusses of a ladder, the raycast has to pierce through and go to the next one. We are working on optimizing this further, but it’s not a bug - it’s a result of how the geometry is set up and has to be processed.

In the example file that you have here, you have around 300 cloned parts, all of which do not have CanCollide enabled. This means that when queryPoint is run, it will call into canOcclude and determine that the object has canCollide set to False. We’re still working on removing the old deprecated methods which should help performance a bit. I’ll update again here once that is turned on, but in the meantime, can you try this replacement script for Popper and tell me if this improves your perf?

QueryPointFix.lua (11.4 KB)

Back when I tested I lowered QUERY_POINT_CAST_LIMIT to determine that it was the script.

In my logs I saw that the same parts were being logged as entryPart.

 

The replacement script doesn’t have the performance issue.

I’d like to make a correction to above script actually, excludeParams.RespectCanCollide should always be set to true. The only reason the camera intersects with the circular surfaces is, because it runs into the max depth. includeParams.RespectCanCollide should be set to false.

Yeah, the re-production steps was mimicking something a game was doing, and maybe a few other games. Not purely random. This were for games that had some kind of systems, such as Spray Paints.

Originally, what one could do is to have a separate collision group, that doesn’t collide with Default, so it could collide with its own world and nothing can ever interfer with it.

 

I think the above script changed local QUERY_POINT_CAST_LIMIT = 5 or not sure which or what was edited. the Disabled one in the re-pro step was a slight modification, that I don’t remember because the re-production place file is old.

 

Changed these.

Okay, well there’s multiple. I guess all?

Okay, yes all seems to work because the CanCollide walls with no collision wouldn’t go through the camera before.

 

Summary

Also regarding that QUERY_POINT_CAST_LIMIT

Not too sure but there’s still something happening.

But if I set it to 64, it can do this. It depends on the angle. I basically just like pretended to “slice” the circles but by moving the camera through them instead. And from there I found some angle.

I think with 5 as well, but just less. But I think 5 means that it will only pierce 5 times, not sure.

I also put a print somewhere once, while the print works, it’s wasn’t the best for the MicroProfiler, not sure if there’s a better approach. Maybe there’s one with Roblox Instances instead of the Output Window, but haven’t tried.

 

If I mix CanCollide with true and false though it still does some things.