I wish to load a class async in c++, what is the common / cleanest way to do this? In my thoughts it would be a “oneliner”:
#include "Async/Async.h"
TWeakObjectPtr<ULazyMe> WeakThis(this);
Async(EAsyncExecution::TaskGraph, [&WeakThis]() {
if (ULazyMe* StrongThis = WeakThis.Get()) {
StrongThis->GetLazyContent().LoadSynchronous();
}
});
Actually surprised there isn’t something like this:
TSoftClassPtr<ULazyThat> That(xxxxxxx);
That->LoadAsync(InDelegate);
However, when I look at the CommonUI code I see a whole lot of funny stuff (overcomplication?). Simplified:
TWeakObjectPtr<ULazyMe> WeakThis(this);
UAssetManager::GetStreamableManager().RequestAsyncLoad(GetLazyContent().ToSoftObjectPath(), [WeakThis]() {
ULazyMe* StrongThis = WeakThis.Get();
if (IsValid(StrongThis)) {
StrongThis->DoStuff(StrongThis->GetLazyContent().Get());
}
}
, FStreamableManager::AsyncLoadHighPriority
);
Am I supposed to add that bunch where I want something async?