Hello everyone, I am trying to make a C++ blueprint function library, but for some reason it won’t appear on the content browser (in spite of showing up on the file explorer).
This is particularly odd since my other function library does show up and work in-engine (ForceUpdateSpectatorStatus).
The goal was to create a blueprint node that lets me copy a skeleton’s bone transforms to another. With the main use case being to copy poses to spawned rag dolls when a player dies, without relying on overly expensive animation blueprints.
//// USkeletalMeshFunctionLibrary.h ////
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "SkeletalMeshFunctionLibrary.generated.h"
UCLASS()
class UnknownElement_API USkeletalMeshFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "SkeletalMesh")
static void CopySkeletalTransforms(USkeletalMeshComponent* SourceMesh, USkeletalMeshComponent* TargetMesh);
};
//// USkeletalMeshFunctionLibrary.cpp ////
#include "SkeletalMeshFunctionLibrary.h"
#include "Components/SkeletalMeshComponent.h"
void USkeletalMeshFunctionLibrary::CopySkeletalTransforms(USkeletalMeshComponent* SourceMesh, USkeletalMeshComponent* TargetMesh)
{
if (!SourceMesh || !TargetMesh)
{
UE_LOG(LogTemp, Warning, TEXT("SourceMesh or TargetMesh is null"));
return;
}
const USkeleton* SourceSkeleton = SourceMesh->SkeletalMesh->GetSkeleton();
const USkeleton* TargetSkeleton = TargetMesh->SkeletalMesh->GetSkeleton();
if (SourceSkeleton != TargetSkeleton)
{
UE_LOG(LogTemp, Warning, TEXT("Source and Target meshes do not share the same skeleton"));
return;
}
const TArray<FTransform>& SourceTransforms = SourceMesh->GetComponentSpaceTransforms();
TArray<FTransform>& TargetTransforms = TargetMesh->GetEditableComponentSpaceTransforms();
if (SourceTransforms.Num() != TargetTransforms.Num())
{
UE_LOG(LogTemp, Warning, TEXT("Source and Target meshes do not have the same number of bones"));
return;
}
for (int32 BoneIndex = 0; BoneIndex < SourceTransforms.Num(); ++BoneIndex)
{
TargetTransforms[BoneIndex] = SourceTransforms[BoneIndex];
}
TargetMesh->MarkRefreshTransformDirty();
TargetMesh->RefreshBoneTransforms();
TargetMesh->RefreshSlaveComponents();
TargetMesh->UpdateComponentToWorld();
}
I’ve built and re-built the code time and time again, both from VS and from the Engine using Tools -> Refresh Project
, no errors in the engine, no changes, no nothing.
I must make it clear that I don’t know C++, this is cobbled together from random sources. I’ve been trying to keep my project blueprints-only (particularly because I can’t financially afford to spend time getting a CS degree, or to spend weeks on end watching and failing to follow tutorials). I do have plenty of experience with C# however, which has not been helpful whatsoever.
As far as I can tell, this code should run. Or at the very least show up in the engine with errors. It has been about a week or so since I started with this. Iteration after iteration of C++, always resulting in either nothing at all, or an engine crash when trying to open the engine.
Now, you might be wondering if this might be due to errors. I wonder that too, but have no idea since Visual Studio (which I have re-installed about 5 times now, including ALL additional packages, including the ones that are now considered optional for current engine versions since they are supposed to come included with the engine) is currently making up errors on its own. I hate this IDE.
For additional context: my other function library in the exact same folder does get colour coded by VS. And it works.
After a week of trial and error, I have no idea what is wrong, or what can be done to fix this. I’m considering cutting my losses and just letting rag dolls spawn in a T-pose.