CPU or GPU skinning, how does the Engine decide which one to use?
I found that for some of my skeletal meshes, unreal is using GPU skinning while for others, it is using CPU.
More specifically, UE4 seems to be using CPU skinning for meshes with higher vert count, which seems weird to me and is causing performance issues for my game.
So, why is the Ungine doing this and is there a setting somewhere to force GPU skinning?
In the editor
If you look around the source code:
return bCPUSkinning || bDrawBoneInfluences ||
bDrawNormals || bDrawTangents ||
bDrawBinormals || bDrawMorphTargetVerts;
(you could hardcode return false as an extreme measure)
In terms of UI in your content browser double click/open a skeletal mesh asset, then go to the Mesh editor
In “Show” → “Advanced” → enable “CPU Skinning” and voila!
You’ll notice that if you enable normals, tangents or binormals it will enable CPU skinning as well.
Now on the C++ side
In the code there is a function:
void USkinnedMeshComponent::GetCPUSkinnedVertices(TArray& OutVertices, int32 InLODIndex)
that will allow you to copy skeletal mesh vertices to CPU. Looking at the implementation you’ll deduce that to enable CPU skinning of a USkinnedMeshComponent you need to do:
Ptr-> USkinnedMeshComponent::bCPUSkinning = true;
FlushRenderingCommands(); // from #include “RenderingThread.h”
Ref: [Get Access to SkeletalMesh Vertices in UE4 | Noah Zuo's Blog]
That being said since 4.24 USkinnedMeshComponent::bCPUSkinning is deprecated and the more straightforward USkinnedMeshComponent::SetCPUSkinningEnabled() was introduced.
UI also changed, when I tested it in 4.26 it was still in the viewport menu but under the “Character” menu this time:
Bonus: to draw a bone’s skinning weight, go to “Character → Mesh → Selected Bone Weight”
As expected it will automatically enable CPU skinning too: