How to get skeletal mesh vertex positions after a morph is applied

I’m trying to get vertex positions after all morphs are applied. I’m able to get vertex positions transformed by bones, but not transformed by the morphs. I took a loo into SkinVertices in SkeletalRenderCPUSkin.cpp as suggested in Morph Targets don't update Bounds? - Rendering - Unreal Engine Forums, but I’m not able to determine what exactly gets teh morphed vertex position. I tried just copying the method wholesale but I can’t make out how to use VertexType as I can’t include ProxyLODMeshTypes.h as it’s part of a plugin and I just can’t seem to include it correctly.

This is my current code below. It crashes when run. Without the big for loop in the middle it works to get vertex positions after bone deformation but adding it in I get an error.


bool UCustomFunctionLibrary::AnimatedVertex__GetAnimatedVertexLocations(USkeletalMeshComponent* Mesh, TArray<FVector>& Locations, TArray<FMatrix>& CacheToLocals, int32 LOD_Index, bool PerformPawnVelocityCorrection)
	if (!Mesh) { return false; }

	//~~~~~~~~~~~~~ Locations.Empty(); //~~~~~~~~~~~~~
	FSkeletalMeshLODRenderData& LOD = Mesh->GetSkeletalMeshRenderData()->LODRenderData[LOD_Index];
	FSkinWeightVertexBuffer& Buffer = LOD.SkinWeightVertexBuffer;

	//Output current locals to variable
	Mesh->GetCurrentRefToLocalMatrices(CacheToLocals, LOD_Index);

	Mesh->ComputeSkinnedPositions(Mesh, Locations, CacheToLocals, LOD, Buffer);

	for (int i = 0; i < Locations.Num(); i++)
		int32 SectionIndex;
		int32 VertexBufferBaseIndex;
		LOD.GetSectionFromVertexIndex(i, SectionIndex, VertexBufferBaseIndex);
		FSkelMeshRenderSection Section = LOD.RenderSections[SectionIndex];

		// Prefetch all bone indices
		const FBoneIndexType* BoneMap = Section.BoneMap.GetData();
		FPlatformMisc::Prefetch(BoneMap, PLATFORM_CACHE_LINE_SIZE);
		const int32 NumSoftVertices = Section.GetNumVertices();
		if (NumSoftVertices > 0)
			for (int32 VertexIndex = VertexBufferBaseIndex; VertexIndex < NumSoftVertices; VertexIndex++)
				const int32 VertexBufferIndex = Section.GetVertexBufferIndex() + VertexIndex;
				const FVector& VertexPosition = LOD.StaticVertexBuffers.PositionVertexBuffer.VertexPosition(VertexBufferIndex);
				FPlatformMisc::Prefetch(&VertexPosition, PLATFORM_CACHE_LINE_SIZE);	// Prefetch next vertices
				Locations[i] = Locations[i] + VertexPosition;

	FTransform ToWorld = Mesh->GetComponentTransform(); FVector WorldLocation = ToWorld.GetLocation();

	//Pawn Velocity Correction UPawnMovementComponent* MovementComp = nullptr; if(PerformPawnVelocityCorrection) { APawn* Pawn = Cast<APawn>(Mesh->GetOwner()); MovementComp = (Pawn) ? Pawn->GetMovementComponent() : NULL; } bool DoVelocityCorrection = PerformPawnVelocityCorrection && MovementComp; //Pawn Velocity Correction

	for (FVector& EachVertex : Locations) 
		EachVertex = WorldLocation + ToWorld.TransformVector(EachVertex); 
		//if (PerformPawnVelocityCorrection) 
		//	EachVertex += MovementComp->Velocity * FApp::GetDeltaTime(); 

	return true;


Fatal error: [File:D:\Build\++UE4\Sync\Engine\Source\Runtime\RenderCore\Private\RenderResource.cpp] [Line: 128] A FRenderResource was deleted without being released first!

UE4Editor_Core!FDebug::AssertFailed() [d:\build\++ue4\sync\engine\source\runtime\core\private\misc\assertionmacros.cpp:425]
UE4Editor_RenderCore!FRenderResource::~FRenderResource() [d:\build\++ue4\sync\engine\source\runtime\rendercore\private\renderresource.cpp:128]

Does anyone have any suggestions? I’ve been digging into this for hours and I just can’t make it work. Mostly because I don’t understand the underlying code in the rendering pipeline. Rendering is not my forte.

use const reference to fix crash

line 6: const FSkeletalMeshLODRenderData& LOD = Mesh->GetSkeletalMeshRenderData()->LODRenderData[LOD_Index];

line 19: const FSkelMeshRenderSection &Section = LODData.RenderSections[SectionIndex];

However looks like this solution doesn’t give right morph target positions…

Did you find a way to make it move with blendshapes?