Hey!
I’m currently creating an LOD system for procedural meshes. The idea is that I would turn on the LOD mesh when the camera is far enough away and turn off the detailed mesh.
Currently, I’m doing this by using the setVisiblity function of the procedural mesh component. I turn off/on the visibility at the same time.
This however gives two problems:
- Occasionally neither object is visible for one frame. So when swapping there’s an empty frame in between. This happens despite that one is made visible and the other hidden immediately after each other, within the same frame, as is seen in the code below.
- When swapping ProceduralMeshComponents this way I get massive framedrops. On a fast PC a single frame can take as long as 200ms when swapping. As you can see in the screenshot below, this time seems to be spent in AddPrimitive, which makes little sense to me because I’m not creating or adding anything, just switching visibility.
Also, some notes:
- The reason I’m doing it this way is that ProceduralMeshComponent doesn’t seem to support LOD levels at all.
- In the code below each LOD level is a separate Actor. I also tried having one Actor with each LOD level as a ProceduralMeshComponent inside that, but that had the same problems.
- I also tried using SwitchActor, but that too had the same problems.
- Same for using SetActorHiddenInGame() instead of SetVisibility().
- The reason you see more than one AddPrimitive per frame in Unreal Insights below is that I have a bunch of different objects all swapping LODs like this.
- This is in Unreal 4.26.
Code:
if (newLOD != previousLOD)
{
lodActors[previousLOD]->proceduralMeshComponent->SetVisibility(false);
lodActors[newLOD]->proceduralMeshComponent->SetVisibility(true);
previousLOD = newLOD;
}
Unreal insights:
Any ideas?
Thanks in advance.