Download

Loading UCurveVector with FObjectFinder - what am I missing?

Hi. I have some static functions that I use to help load assets in Actor constructors. I have one that works fine for loading UCurveFloat assets. I now want to load UCurveVector assets but I’m getting a compile error.




Error C2664 'void ConstructorHelpers::ValidateObject(UObject *,const FString &,const TCHAR *)': cannot convert argument 1 from 'T *' to 'UObject *' IdonixGraphics C:\Program Files\Epic Games\UE_4.25\Engine\Source\Runtime\CoreUObject\Public\UObject\ConstructorHelpers.h 110



This is the code I’m using to load the asset




UCurveVector* UGraphicUtilities::GetCurveVector(const FString& moduleName, const FString& assetName)
{
// Example reference path: "CurveVector'/MyProject/Curves/Curve_VLinearCurve.Curve_VLinearCurve'"

TArray<FStringFormatArg> args;
args.Add(FStringFormatArg(moduleName));
args.Add(FStringFormatArg(assetName));
FString assetPath = FString::Format(TEXT("CurveVector'/{0}/Curves/{1}.{1}'"), args);

ConstructorHelpers::FObjectFinder<UCurveVector> asset(*assetPath);
return asset.Object;
}



Both UCurveFloat and UCurveVector inherit from UCurveBase so there shouldn’t be any differences? I’ve got all the relevant includes too just incase but no good.



#include "CoreMinimal.h"
#include "EngineGlobals.h"
#include "Curves/RichCurve.h"
#include "Curves/CurveBase.h"
#include "Misc/DefaultValueHelper.h"
#include "UObject/ObjectMacros.h"


So, what am I missing?

Ok, so it seems that merely forward declaring the UCurveVector in the header file isn’t enough. Adding the #include “Curves/CurveVector.h” to the header file solved it.