UE5 ERROR for using USkinnedMeshComponent

Hi hope yall doing well.
I have this c++ bluepring function library for getting character vertices which works fine in UE4 but when using same thing in UE5 it says :arrow_down:

warning C4996: ‘USkinnedMeshComponent::SkeletalMesh’: Replaced by SkinnedAsset. Use GetSkinnedAsset()/SetSkinnedAsset() instead, or GetSkeletalMeshAsset/SetSkeletalMeshAsset() when called from a USkeletalMeshComponent. Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.

I dont know how to replace USkinnedMeshComponent in my code with what UE5 suggesting.

MY CODE :arrow_down:



Thanks everyone :slightly_smiling_face:

1 Like

Has anyone solved this?? I get same error,

// Copyright Epic Games, Inc. All Rights Reserved.

#include "BPLibraryFuncs.h"
#include "SkeletalRenderPublic.h"
#include "Rendering/SkeletalMeshRenderData.h"
#include "GameFramework/PawnMovementComponent.h"
#include "Kismet/KismetMathLibrary.h" 
#include "SkeletalMeshTypes.h"

UBPLibraryFuncs::UBPLibraryFuncs(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{}



bool UBPLibraryFuncs::BP_GetSkeletalMeshVertexLocations(USkeletalMeshComponent* Mesh, TArray<FVector3f>& Locations, int32 LODIndex)
{
	if (!Mesh || !Mesh->SkeletalMesh) return false;

	//CPU or GPU skinning
	if (Mesh->GetCPUSkinningEnabled()) {
		TArray<FFinalSkinVertex> SkinnedVertices;
		Mesh->GetCPUSkinnedVertices(SkinnedVertices, LODIndex);
		Locations.Empty();
		Locations.AddUninitialized(SkinnedVertices.Num());

		for (int32 i = 0; i < SkinnedVertices.Num(); ++i) {
			Locations[i] = SkinnedVertices[i].Position;
		}
	}
	else {

		const FSkeletalMeshRenderData* RenderData = Mesh->GetSkeletalMeshRenderData();
		if (!RenderData) return false;
		FSkinWeightVertexBuffer& SkinWeightBuffer = *Mesh->GetSkinWeightBuffer(LODIndex);
						
		const FSkeletalMeshLODRenderData& LOD = RenderData->LODRenderData[LODIndex];
		const FSkinWeightVertexBuffer& Buffer = LOD.SkinWeightVertexBuffer;
		TArray<FMatrix44f> CacheToLocals;				
		Mesh->GetCurrentRefToLocalMatrices(CacheToLocals, LODIndex);
		Mesh->ComputeSkinnedPositions(Mesh, Locations, CacheToLocals,LOD, Buffer);
	}

	const FTransform ToWorld = Mesh->GetComponentTransform();
	for (FVector3f& EachVertex : Locations) {
		EachVertex = (FVector3f)ToWorld.TransformPosition((FVector)EachVertex);
	}
	return true;
}

void UBPLibraryFuncs::BP_SetCPUSkinningEnabled(USkinnedMeshComponent* Mesh, bool bEnable, bool bRecreateRenderStateImmediately)
{
	Mesh->SetCPUSkinningEnabled(bEnable, bRecreateRenderStateImmediately);
}

Thanks!

I manged to get everything to compile after changing my code to use SkinnedAsset rather than SkeletalMesh:

//From:
SkeletalMesh = Context.AnimInstanceProxy->GetSkelMeshComponent()->SkeletalMesh;

//To:
SkeletalMesh = Context.AnimInstanceProxy->GetSkelMeshComponent()->GetSkinnedAsset();

Everything appears to be working now.