Hi guys, I’m trying to load a stream level not in the main thread.
We have big levels and we want to decrease the loading time for console, so I thought I’d be a good idea to load the rest of levels in a secondary thread.
I’m using a C++ class that inherits from FNonAbandonableTask, but I’m struggling when I type the LoadStreamLevel function because I can’t access to the GetWorld function, I can’t select a WorldContext, so I can’t stream the level… Any help?
class AStreamLevelLoaderTask : public FNonAbandonableTask
{
public:
AStreamLevelLoaderTask(FName _levelToLoad);
~AStreamLevelLoaderTask();
void DoWork();
// required by UE4, is required
FORCEINLINE TStatId GetStatId() const
{
RETURN_QUICK_DECLARE_CYCLE_STAT(LoadLevelTask, STATGROUP_ThreadPoolAsyncTasks);
}
protected:
FName LevelToLoad;
AStreamLevelLoaderTask::AStreamLevelLoaderTask(FName _levelToLoad)
{
}
AStreamLevelLoaderTask::~AStreamLevelLoaderTask()
{
this->Abandon();
}
void AStreamLevelLoaderTask::DoWork()
{
// The place where the main action
}