PolySpatial ConvertMeshAssetToPolySpatialMesh seems called too often

Hi, I’m working on a Vision OS project using Unity 2022.3.21 and PolySpatial 1.2.3.

I’m investigating the ConvertMeshAssetToPolySpatialMesh line, which runs 51 times per frame and takes 10 milliseconds. I’m unsure if there’s an issue here.

I’m using an Xcode release build with the profiler attached. I know that updating meshes can be expensive with RealityKit, but it’s unlikely that I’m updating the mesh 51 times per frame. Typically, within a single frame, I update around 4 meshes for MeshFilter and less than 10 meshes for MeshCollider. However, the number of times ConvertMeshAssetToPolySpatialMesh runs is not an outliner, often exceeding 100 times in many frames.

I’m curious about the updating logic for PolySpatial. Generally, when does RealityKit submit a property for updating? In the meantime, I’ll try to create a minimal reproducible code.

1 Like

experiencing a similar issue as well

Do you have UGUI elements in your scene? The meshes for those have to be converted as well.

Generally speaking, when something changes (for instance, when a mesh is updated), we flag it as dirty. Then, once per frame (after the late update), we transmit everything that has changed on that frame.

That would be great! If you can submit a repro case as a bug report and let us know the incident number (IN-#####), we can investigate.

1 Like

Yes, indeed! I’ve noticed that it accounts for three function calls, but not all of them.

I’ve tried to break down the problem, but it seems that the logic for updating the mesh is solid – no bugs here! :blush: Good work!

However, I do have some new findings:

  1. The culprit appears to be the Particle System! We’re using the ‘Bake To Mesh’ method, and removing all particle systems significantly increases the FPS. I found this line in the documentation. Do you already have any solutions in mind?
  1. The ConvertMeshAssetToPolySpatialMesh function seems to have a pretty high overhead. You can see that the least time function call in the profiling uses 0.1 ms.

Yes; as of the visionOS 2.0 beta, there is a new API that should allow us to improve performance in many cases where we need to generate meshes at run time. However, I don’t yet have a timeline for when we will convert particles to using the new API.

Thanks; that’s good to know! This is another case where the LowLevelMesh API should allow us to improve performance. Again, though, that API was just released; it will take us a little longer to integrate it into PolySpatial.

1 Like