ConstructorHelper.succeeded()

The code below does not work. Some weird message about a conversion problem and “loses qualifiers”.

When I remove the if (SkeletalMeshObj.Succeeded()) check it will work. Also if I only remove the “const” keyword it will work. For some reason .succeeded() does not work with a const. Why?

const ConstructorHelpers::FObjectFinder<USkeletalMesh> SkeletalMeshObj(TEXT("/Game/AnimationAssets/UE4_Mannequin/Mesh/SK_Mannequin"));
if (SkeletalMeshObj.Succeeded()) // remove const-keyword in the above line and this will no longer crash.
{
	GetMesh()->SetSkeletalMesh(SkeletalMeshObj.Object);
	GetMesh()->SetRelativeLocation(FVector(0.0f, 0.0f, -90.0f));
	GetMesh()->SetRelativeRotation(FRotator(0.0f, -90.0f, 0.0f));
}
else
{
}

In C++ any function called on a const object must guarantee that it will not change the state of the object (and thus be a const function itself).

Succeded() does not fulfill this criteria. If you look at ConstructorHelpers.h it is declared simply as bool Succeeded().

So unless it were implemented as * bool Succeeded() const * you will not be allowed to invoke it on a constant instance of FObjectFinder as doing so would cause it to “lose” its const qualifier.

HTH.