I’ve followed a tutorial that shows how to create a separate thread to run some background tasks within unreal.
I have a plugin that loads a file and the need to parse the file in order to render a 3D object. This locks the UI up so getting this loaded to a separate thread is pretty important.
The Errors that I’m getting are the following
CompilerResultsLog: [3/6] LoaderBPFunctionLibrary.cpp
CompilerResultsLog: C:\Program Files\Epic Games\UE_4.25\Engine\Source\Runtime\Core\Public\Async/AsyncWork.h(150) : error C4624: 'FAutoDeleteAsyncTask<LoadTask>': destructor was implicitly defined as deleted
CompilerResultsLog: C:\Users\Matthew Wallace\Development\Unreal Engine\FulcrumVR\Plugins\FcrmMeshLoader\Source\FcrmMeshLoader\Private\LoaderBPFunctionLibrary.cpp(108): note: see reference to class template instantiation 'FAutoDeleteAsyncTask<LoadTask>' being compiled
CompilerResultsLog: C:\Program Files\Epic Games\UE_4.25\Engine\Source\Runtime\Core\Public\Async/AsyncWork.h(150) : error C2282: 'FAutoDeleteAsyncTask<LoadTask>::~FAutoDeleteAsyncTask' cannot override 'IQueuedWork::~IQueuedWork'
CompilerResultsLog: C:\Program Files\Epic Games\UE_4.25\Engine\Source\Runtime\Core\Public\Misc/IQueuedWork.h(40): note: 'IQueuedWork::~IQueuedWork' is not deleted
CompilerResultsLog: C:\Users\Matthew Wallace\Development\Unreal Engine\FulcrumVR\Plugins\FcrmMeshLoader\Source\FcrmMeshLoader\Private\LoaderBPFunctionLibrary.cpp(116) : error C2248: 'LoadTask::LoadTask': cannot access private member declared in class 'LoadTask'
CompilerResultsLog: C:\Users\Matthew Wallace\Development\Unreal Engine\FulcrumVR\Plugins\FcrmMeshLoader\Source\FcrmMeshLoader\Public\LoaderBPFunctionLibrary.h(82): note: see declaration of 'LoadTask::LoadTask'
CompilerResultsLog: C:\Users\Matthew Wallace\Development\Unreal Engine\FulcrumVR\Plugins\FcrmMeshLoader\Source\FcrmMeshLoader\Public\LoaderBPFunctionLibrary.h(79): note: see declaration of 'LoadTask'
CompilerResultsLog: C:\Users\Matthew Wallace\Development\Unreal Engine\FulcrumVR\Plugins\FcrmMeshLoader\Source\FcrmMeshLoader\Private\LoaderBPFunctionLibrary.cpp(117) : error C2248: 'LoadTask::~LoadTask': cannot access private member declared in class 'LoadTask'
CompilerResultsLog: C:\Users\Matthew Wallace\Development\Unreal Engine\FulcrumVR\Plugins\FcrmMeshLoader\Source\FcrmMeshLoader\Public\LoaderBPFunctionLibrary.h(98): note: compiler has generated 'LoadTask::~LoadTask' here
CompilerResultsLog: C:\Users\Matthew Wallace\Development\Unreal Engine\FulcrumVR\Plugins\FcrmMeshLoader\Source\FcrmMeshLoader\Public\LoaderBPFunctionLibrary.h(79): note: see declaration of 'LoadTask'
LogMainFrame: MainFrame: Module compiling took 10.187 seconds
Warning: HotReload failed, recompile failed
Here is what I have thus far.
// Fill out your copyright notice in the Description page of Project Settings.
/// this is the .h
#pragma once
#include "ProceduralMeshComponent.h"
#include "Async/AsyncWork.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "LoaderBPFunctionLibrary.generated.h"
UENUM(BlueprintType)
enum class EPathType : uint8
{
Absolute,
Relative
};
USTRUCT(BlueprintType)
struct FMeshInfo
{
GENERATED_USTRUCT_BODY()
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "ReturnedData")
TArray<FVector> Vertices;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "ReturnedData")
TArray<int32> Triangles;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "ReturnedData")
TArray<FVector> Normals;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "ReturnedData")
TArray<FVector2D> UV0;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "ReturnedData")
TArray<FLinearColor> VertexColors;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "ReturnedData")
TArray<FProcMeshTangent> Tangents;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "ReturnedData")
FTransform RelativeTransform;
};
USTRUCT(BlueprintType)
struct FReturnedData
{
GENERATED_USTRUCT_BODY()
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "ReturnedData")
bool bSuccess;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "ReturnedData")
int32 NumMeshes;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "ReturnedData")
TArray<FMeshInfo> meshInfo;
};
UCLASS()
class FCRMMESHLOADER_API ULoaderBPFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "MeshLoader")
static FReturnedData LoadMesh(FString filepath, EPathType type = EPathType::Absolute);
UFUNCTION(BlueprintCallable, Category = "MeshLoader")
FReturnedData LoadMeshMainThread(FString filepath, EPathType type = EPathType::Absolute);
};
//////====================================================
class LoadTask : public FNonAbandonableTask
{
LoadTask(FString _filepath, EPathType _type, FReturnedData _returnedData);
~LoadTask();
FORCEINLINE TStatId GetStatId() const
{
RETURN_QUICK_DECLARE_CYCLE_STAT(LoadTask, STATGROUP_ThreadPoolAsyncTasks);
}
FString filepath;
EPathType type;
FReturnedData ReturnedData;
void DoWork();
void DoWorkMain();
};
.cpp file
// Fill out your copyright notice in the Description page of Project Settings.
#include "LoaderBPFunctionLibrary.h"
#include "FcrmMeshLoader.h"
#include <assimp/Importer.hpp> // C++ importer interface
#include <assimp/scene.h> // Output data structure
#include <assimp/postprocess.h> // Post processing flags
void FindMeshInfo(const aiScene* scene, aiNode* node, FReturnedData& result)
{
}
void FindMesh(const aiScene* scene, aiNode* node, FReturnedData& retdata)
{
}
FReturnedData ULoaderBPFunctionLibrary::LoadMesh(FString filepath, EPathType type)
{
FReturnedData _returnedData;
(new FAutoDeleteAsyncTask<LoadTask>(filepath, type, _returnedData))->StartBackgroundTask();
return _returnedData;
};
FReturnedData ULoaderBPFunctionLibrary::LoadMeshMainThread(FString filepath, EPathType type)
{
FReturnedData _returnedData;
//LoadTask::LoadTask* task = new LoadTask(filepath, type, _returnedData);
LoadTask* task = new LoadTask(filepath, type, _returnedData);
delete task;
return _returnedData;
};
//==============================================================
LoadTask::LoadTask(FString _filepath, EPathType _type, FReturnedData _returnedData)
{
filepath = _filepath;
type = _type;
ReturnedData = _returnedData;
}
LoadTask::~LoadTask()
{
UE_LOG(LogTemp, Warning, TEXT("Mesh Finished Loading"));
}
void LoadTask::DoWork()
{
}
void LoadTask::DoWorkMain()
{
DoWork();
}