Hi there! I’m having the same issue with UE 5.5.4
I just want to make it a little more clear. In my case, which could be similar with yours, I have a data table called DT_Columns
. Now, watch the hands:
- The class
A
loads this table in constructor and stores insideTObjectPtr<UDataTable>
; - The class
B
loads it same way and stores same way;
During UE startup routine, the A
class constructs successful, but B
cause:
Fatal error: [File:D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\Serialization\AsyncLoading2.cpp] [Line: 9991]
Loading is stuck, flush will never finish
If we move the any of those loading routine into
OnConstruction
overloaded method, the error dissapears.
Here we go. If we change TObjectPtr
with raw pointer in both classes, the error still appears. I guess the resource just cannot be loaded twice asynchronously or whatever, thanks to epics.
I don’t like the idea to break RAII methodology and move all the loadings inside OnConstruction
method, so, the first come in my mind was caching:
TObjectPtr<UDataTable> LoadDataTable(const TCHAR *Path) {
static TMap<FString, TObjectPtr<UDataTable>> DTCache{};
static FCriticalSection DTCacheGuard{};
if (!Path) {
return nullptr;
}
const FScopeLock Lock{ &DTCacheGuard };
if (auto Found{ DTCache.Find(Path) }; Found && *Found) {
return *Found;
}
if (auto Loaded{ LoadObject<UDataTable>(nullptr, Path) }; Loaded) {
DTCache.Add(Path, Loaded);
return Loaded;
}
return nullptr;
}
But it doesn’t work. I wish to find an elegant solution, but the only elegant solution could exist is epic’s solution.
So, don’t load things in constructor and try to not load resources twice. Share them somehow