Download

ConstructorHelpers::FObjectFinder<UStaticMesh> Won't compile

I am attempting to create a visual asset (sphere mesh) in my actor. I am new to Unreal and have seen this sample in many places. However, it won’t compile and I’m not sure why:

// Create and position a mesh component so we can see where our sphere is
UStaticMeshComponent* SphereVisual = CreateDefaultSubobject<UStaticMeshComponent>(TEXT(“VisualRepresentation”));
SphereVisual->SetupAttachment(RootComponent);

static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere"));
if (SphereVisualAsset.Succeeded())
{
SphereVisual->SetStaticMesh(SphereVisualAsset.Object);
SphereVisual->SetRelativeLocation(FVector(0.0f, 0.0f, -40.0f));
SphereVisual->SetWorldScale3D(FVector(0.8f));
}

The compiler error I’m getting is:

D:\ProgramFiles\EpicGames\Epic Games\UE_4.25\Engine\Source\Runtime\CoreUObject\Public\UObject/ConstructorHelpers.h(110): error C2664: ‘void ConstructorHelpers::ValidateObject(UObject *,const FString &,const TCHAR *)’: cannot convert argument 1 from ‘T *’ to ‘UObject *’
with

T=UStaticMesh
]

UStaticMesh is of the correct type though (a UObject).

Have you perhaps defined the symbol “Class” in a macro of some sort? It’s the name of the argument passed into ValidateObject().

If that’s not it, then the problem is that you haven’t included the header for UStaticMesh when you call the template.