Search code examples
c++unreal-engine5

How can I declare this function to return a TFuture? UE5 C++


I have been trying to declare this function in my header file (using ue5 c++) and I get the compiler telling me this error:

Unrecognized type 'TFuture' - type must be a UCLASS, USTRUCT, UENUM, or global delegate. [UnrealHeaderTool ParserError]*

static TFuture<UTexture2D*> ImportImageFromDiskAsync(UObject* Outer, const FString& ImagePath, TFunction<void()> CompletionCallback);

What am I doing wrong here?

Minimal Reproducible Example:


#include "CoreMinimal.h"
#include "PixelFormat.h"
#include "UObject/NoExportTypes.h"
#include "Async/Future.h"
#include "TSImageLoader.generated.h"

// Forward Declare Texture 2D
class UTexture2D;

DECLARE_LOG_CATEGORY_EXTERN(LogTextureSerializeImageLoading, Log, All);

UCLASS(BlueprintType)
class TEXTURESERIALIZEIO_API UTSImageLoader : public UObject
{
    GENERATED_BODY()

public:
UFUNCTION(BlueprintCallable, meta  = (HidePin = "Outer", DefaultToSelf = "Outer"))
static TFuture<UTexture2D*> ImportImageFromDiskAsync(UObject* Outer, const FString& ImagePath, TFunction<void()> CompletionCallback);

};

Solution

  • Okay I figured it out.

    TFuture cannot be returned on a function that would be exposed to blueprints. So removing the UFUNCTION() tag above it solves the issue.