I created a class inherited from UUserWidget and inside the OnFindClicked function I want to run an algorithm that changes some materials but async, I tried so many different ways with FNonAbandonableTask, FRunnable, etc… how can I make it work ?
or is it impossible?
UCLASS()
class MYPATH_API UFindWidget : public UUserWidget
{
GENERATED_BODY()
public:
UPROPERTY(meta = (BindWidget))
class UButton* FindButton;
protected:
UFUNCTION()
void OnFindClicked();
};
// -----
void UFindWidget::OnFindClicked()
{
FMyWorker* MyRunnable = new FMyWorker();
FRunnableThread* MyThread = FRunnableThread::Create(MyRunnable, TEXT(“MyThread”));
// Wait for the thread to finish
MyThread->WaitForCompletion();
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Work Done ")));
}