Hi,

I have been having horrible lag spikes in my game, and have figured out that it's the spine renderer when it's set to create collision. It looks like every few seconds it's calling CreateMeshSection and that causes the FPS to tank.

I've attached an image of the unreal profiler:
Image

Wondering if you guys know a fix for the issue? Unfortunately I need the collision on the different sprites because they all react to mouse events.

Thanks

Related Discussions
...

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:

  1. Open SpineSkeletonRendererComponent.cpp.
  2. Locate the line where CreateMeshSection is called. It should look something like this:
       ProceduralMesh->CreateMeshSection(SectionIndex, Vertices, Triangles, Normals, UV0, Colors, Tangents, true);
  3. 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.

  • Editado

My colleagues will be along Monday to advise, but Unreal performance issues aside, I can say that it's rare to need to do hit detection using region and mesh attachments. Those can rotate/scale/shear, making hit detection more complex. Also the visible region and mesh attachments are not always what you want for the clickable or hit detection area. Sometimes the area needs to be smaller or larger to make sense in the application.

It's almost always better to use circles or axis aligned rectangles for hit detection. You can base the position of these on a bone position.

For example, Street Fighter uses axis aligned rectangles for all hit boxes. It does not use the visuals to define the hit boxes.

    Nate

    Thanks for the reply. Yeah I know in most games they just use something else as a hit box but for my use case it would be much better to use the actual shape of the mesh. I had a play around with things on the weekend and found the spine option to move physics off the game thread, and from I can tell so far that has improved the performance a lot.

    Just curious, how come the CreateMeshSection get's called every few seconds? Is it in case the sprite has changed shape or something? In my case I am only rotating bones so wouldn't have thought it was necessary, but obviously I don't know that much about how it all works under the hood.

    Thanks

    I forgot Mario is out today (Monday), so he won't be able to help until tomorrow. Sorry for the wait!

    I'm not sure what hit detection you are doing. If it's point-polygon using mesh attachment or region attachment vertices, you could do the hit detection manually. Spine has bounding boxes and code for AABB, point-polygon, and segment-polygon intersection in the SkeletonBounds class. Those use any polygon, so you could use them with the hull vertices from a mesh rather than a bounding box. You would transform a game world point into the skeleton coordinate space, then to attachment coordinates, then check intersection.

    If you hit detection is for game world physics or something else that needs Unreal's mesh section, then of course that isn't an option.

    Sorry for the delay. Nate already covered most of the ground, specifically setting up collision shapes in UE, and possibly attaching them to the skeleton via BoneFollower and other components.

    CreateMeshSection does have to be called every frame to recreate meshes. This is non-optional, as it is impossible to track which meshes for attachments have become "dirty". I'm afraid there is no work around for that other then what's already been outlined above.