C++ Code not being found by the engine?

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).
image image

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.

image

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.

1 Like

I was facing the same problem for days with a lot of erros in Visual Studio I fixed this today, chatGPT helped me to fix and make c++ code
I built it out of Visual Studio using CMD

First I disabled “Live Coding” and “Automatically Compile Newly Added C++ Classes” in Editor Preferences
Quit UE
Open CMD and paste
“D:\Program Files\Epic Games\UE_5.3\Engine\Build\BatchFiles\Build.bat” PROJECTNAMEEditor Win64 Development -Project=“D:\PROJECTPATH\PROJECTFOLDER\PROJECT.uproject” -WaitMutex

Change with your path
And then the code appeared to me on UE
Also paste the errors on chatGPT and it will help you to fix them

I don’t know if it has have anything to do with but before doing that I put it in the Environment Variables > System Variables > New…
Name: TRACEDESIGNTIME
Value: true

1 Like

I’m actually able to see the errors this way. Thank you! I’ll try the AI suggestion next, maybe it can figure out the issue faster than I can.

1 Like

The AI says it does not know. I’m getting an error saying Error: Expected an include at the top of the header the follows all other includes: '#include "USkeletalMeshFunctionLibrary.generated.h", but my include is already exactly at the end…


Update:
I just noticed that I had #include "SkeletalMeshFunctionLibrary.generated.h" instead of #include "USkeletalMeshFunctionLibrary.generated.h" and neither me, nor the AI, noticed until now.

I’m ready to believe that AGI is here, the machine is just as dumb as me lol.

I’m currently building, I sure hope this works…

1 Like

You did it! This was the solution!

I decided to try some other AI tools and one called “Unreal Engine 5 Expert” was able to instantly figure out all my mistakes. Thank you!

Since this code is now more machine than man, it is unfair that I keep it to myself, particularly since it might be useful for others. So while I haven’t tested it yet, here is a copy of the “fixed” code:

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "USkeletalMeshFunctionLibrary.generated.h"

UCLASS()
class UNKNOWNELEMENT_API USkeletalMeshFunctionLibrary : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()

public:
    UFUNCTION(BlueprintCallable, Category = "SkeletalMesh")
    static void CopySkeletalTransforms(USkeletalMeshComponent* SourceMesh, USkeletalMeshComponent* TargetMesh);
};
#include "USkeletalMeshFunctionLibrary.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->GetSkeletalMeshAsset()->GetSkeleton();
    const USkeleton* TargetSkeleton = TargetMesh->GetSkeletalMeshAsset()->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->RefreshBoneTransforms();
    TargetMesh->RefreshFollowerComponents();
    TargetMesh->UpdateComponentToWorld();
}

Update: It compiled, but it does not actually work as I want it to. Nevertheless, I’m off to celebrate. I’ll write a reply with the final code when I have it.

1 Like

I see you understand more of codes than me :joy:
I was using that UE5 Expert :fire:
Hope you fix this

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.