The lag spikes you are experiencing are likely due to the collision mesh generation in the Spine renderer. This is a known issue with the Unreal Engine's handling of procedural mesh components, which can cause significant performance problems when collision meshes are updated frequently.
To mitigate this issue, you can disable the collision mesh generation in the Spine renderer. Here are the steps to do so:
- Open
SpineSkeletonRendererComponent.cpp
.
- Locate the line where
CreateMeshSection
is called. It should look something like this:
ProceduralMesh->CreateMeshSection(SectionIndex, Vertices, Triangles, Normals, UV0, Colors, Tangents, true);
- Change the last argument from
true
to false
to disable collision mesh generation:
ProceduralMesh->CreateMeshSection(SectionIndex, Vertices, Triangles, Normals, UV0, Colors, Tangents, false);
After making this change, ensure that the code is completely recompiled by closing any running UE4 instance, then in Visual Studio, right-click the solution in the solution explorer, and click "Clean build". You can then trigger another build as usual.
If you still need collision detection, you will have to create custom collision shapes and attach them to your actors manually. This approach avoids the performance hit from updating procedural collision meshes every frame.
For more information, you can refer to the following discussion on the issue:
spine-runtimes/SpineSkeletonRendererComponent.cpp at 3.6
Additionally, you can follow the issue on GitHub for updates:
[ue4] Collision mesh generation hogs performance · #1026](EsotericSoftware/spine-runtimesissues/1026)
By disabling collision mesh generation and using custom collision shapes, you should see a significant improvement in performance.