LoadPackageAsync
LoadPackageAsync
#Overview
name: LoadPackageAsync
This variable is created as a Console Variable (cvar).
- type:
Cmd
- help:
Loads packages async by names. Usage: LoadPackageAsync <package name> [<package name> ...]
It is referenced in 51
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of LoadPackageAsync is to asynchronously load a package and all contained objects that match context flags. It is primarily used for loading game assets and levels in a non-blocking manner.
Key points about LoadPackageAsync:
-
It’s part of the Unreal Engine’s asset loading system, used across various subsystems including level streaming, material loading, and asset management.
-
The value is typically set by calling the function with a package name or path, along with optional parameters like completion delegates and priority.
-
It interacts with the AsyncLoading subsystem and can be affected by settings like GAsyncLoadingAllowed.
-
Other variables that interact with it include AsyncLoadingThread, GIsInitialLoad, and various async loading flags.
-
Developers must be aware that:
- It’s non-blocking, so you need to handle completion properly.
- It can fail if the package doesn’t exist or can’t be loaded.
- It may have performance implications if overused.
-
Best practices include:
- Using completion delegates to handle loaded assets.
- Managing priorities for critical assets.
- Avoiding excessive async loads, especially during performance-critical sections.
- Properly handling load failures.
- Considering package dependencies when loading multiple related assets.
LoadPackageAsync is a crucial function for managing asset loading in Unreal Engine, allowing for more efficient and responsive gameplay by loading assets in the background.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Private/Serialization/AsyncPackageLoader.cpp:110
Scope: file
Source code excerpt:
static FAutoConsoleCommand CVar_LoadPackageAsyncCommand(
TEXT("LoadPackageAsync"),
TEXT("Loads packages async by names. Usage: LoadPackageAsync <package name> [<package name> ...]"),
FConsoleCommandWithArgsDelegate::CreateStatic(LoadPackageAsyncCommand));
#endif
const FName PrestreamPackageClassNameLoad = FName("PrestreamPackage");
#Loc: <Workspace>/Engine/Plugins/Developer/Concert/ConcertSync/ConcertSyncClient/Source/ConcertSyncClient/Private/ConcertClientSequencerManager.cpp:997
Scope (from outer to inner):
file
function void FConcertClientSequencePreloader::OnPreloadEvent
Source code excerpt:
UE_LOGFMT(LogConcertSequencerSync, Verbose, "OnPreloadEvent: Initiating async package load for {Path}", SequenceObjectPath.ToString());
PreloadPendingSequences.Add(SequenceObjectPath, SoftSequenceObject);
LoadPackageAsync(SoftSequenceObject.GetLongPackageName(), FLoadPackageAsyncDelegate::CreateLambda(
[WeakThis = AsWeak(),
WeakRequestSession = WeakSession,
SequenceObjectPath,
SoftSequenceObject]
(const FName& PackageName, UPackage* LoadedPackage, EAsyncLoadingResult::Type Result)
{
#Loc: <Workspace>/Engine/Plugins/Enterprise/VariantManagerContent/Source/VariantManagerContent/Private/LevelVariantSetsActor.cpp:29
Scope (from outer to inner):
file
function ULevelVariantSets* ALevelVariantSetsActor::GetLevelVariantSets
Source code excerpt:
if (IsAsyncLoading())
{
LoadPackageAsync(LevelVariantSets.GetLongPackageName());
return nullptr;
}
else
{
return Cast<ULevelVariantSets>(LevelVariantSets.TryLoad());
}
#Loc: <Workspace>/Engine/Plugins/Experimental/Avalanche/Source/Avalanche/Private/Framework/AvaSoftAssetPtr.cpp:35
Scope (from outer to inner):
file
function EMotionDesignAssetType FAvaSoftAssetPtr::GetAssetType
Source code excerpt:
{
// Todo: problem with loading the asset sync here.
// Todo: Investigate LoadPackageAsync.
// This will cause a hitch. For level asset, we want to avoid that.
UObject* LoadedSourceAsset;
{
TRACE_CPUPROFILER_EVENT_SCOPE(FAvaSoftAssetPtr::LoadSourceAsset);
const FSoftObjectPtr SourceAsset(AssetPtr.ToSoftObjectPath());
LoadedSourceAsset = SourceAsset.LoadSynchronous();
#Loc: <Workspace>/Engine/Plugins/Experimental/Avalanche/Source/AvalancheMedia/Private/Playback/AvaPlaybackManager.cpp:364
Scope (from outer to inner):
file
function UAvaPlaybackGraph* FAvaPlaybackManager::LoadPlaybackObject
Source code excerpt:
}
// Todo: Investigate LoadPackageAsync.
// For now, we tolerate a sync load here because there will be hitch from converting the
// Motion Design Asset to a world.
TempPackage = LoadPackage(nullptr, *PackageName, LOAD_None );
}
if (TempPackage)
#Loc: <Workspace>/Engine/Plugins/MovieScene/TemplateSequence/Source/TemplateSequence/Private/TemplateSequenceActor.cpp:133
Scope (from outer to inner):
file
function void ATemplateSequenceActor::InitializePlayer
Source code excerpt:
else
{
LoadPackageAsync(TemplateSequence.GetLongPackageName(), FLoadPackageAsyncDelegate::CreateUObject(this, &ATemplateSequenceActor::OnSequenceLoaded));
}
}
}
void ATemplateSequenceActor::OnSequenceLoaded(const FName& PackageName, UPackage* Package, EAsyncLoadingResult::Type Result)
{
#Loc: <Workspace>/Engine/Plugins/Runtime/GameFeatures/Source/GameFeatures/Private/GameFeatureAction_AddCheats.cpp:82
Scope (from outer to inner):
file
function void UGameFeatureAction_AddCheats::OnCheatManagerCreated
Source code excerpt:
TWeakObjectPtr<UGameFeatureAction_AddCheats> WeakThis(this);
TWeakObjectPtr<UCheatManager> WeakCheatManager(CheatManager);
LoadPackageAsync(CheatManagerClassPtr.GetLongPackageName(), FLoadPackageAsyncDelegate::CreateLambda(
[WeakThis, WeakCheatManager, CheatManagerClassPtr](const FName& PackageName, UPackage* Package, EAsyncLoadingResult::Type Result)
{
if (Result == EAsyncLoadingResult::Succeeded)
{
UGameFeatureAction_AddCheats* StrongThis = WeakThis.Get();
UCheatManager* StrongCheatManager = WeakCheatManager.Get();
#Loc: <Workspace>/Engine/Plugins/Runtime/Metasound/Source/MetasoundEditor/Private/MetasoundEditorModule.cpp:295
Scope (from outer to inner):
file
namespace Metasound
namespace Editor
class class FModule : public IMetasoundEditorModule
function void LoadAndRegisterAsset
Source code excerpt:
}
};
LoadPackageAsync(AssetPath.GetLongPackageName(), FLoadPackageAsyncDelegate::CreateLambda(LoadAndRegister));
}
}
void AddClassRegistryAsset(const FAssetData& InAssetData)
{
using namespace Frontend;
#Loc: <Workspace>/Engine/Plugins/Runtime/SoundMod/Source/SoundMod/Private/SoundNodeModPlayer.cpp:38
Scope (from outer to inner):
file
function void USoundNodeModPlayer::LoadAsset
Source code excerpt:
{
bAsyncLoading = true;
LoadPackageAsync(LongPackageName, FLoadPackageAsyncDelegate::CreateUObject(this, &USoundNodeModPlayer::OnSoundModLoaded, bAddToRoot));
}
}
else if (bAddToRoot)
{
SoundMod->AddToRoot();
}
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Cooker/CookPackageData.cpp:998
Scope (from outer to inner):
file
namespace UE::Cook
function bool FPackageData::TryPreload
Source code excerpt:
PackageDatas.GetMonitor().OnPreloadAllocatedChanged(*this, true);
AsyncRequest = MakeShared<FAsyncRequest>();
AsyncRequest->RequestID = LoadPackageAsync(
GetFileName().ToString(),
FLoadPackageAsyncDelegate::CreateLambda(
[AsyncRequest = AsyncRequest](const FName&, UPackage*, EAsyncLoadingResult::Type) { AsyncRequest->bHasFinished = true; }
),
32 /* Use arbitrary higher priority for preload as we're going to need them very soon */
);
#Loc: <Workspace>/Engine/Source/Runtime/Core/Public/Misc/CoreDelegates.h:96
Scope: file
Source code excerpt:
static CORE_API TMulticastDelegate<void(const FString&)> OnAsyncLoadPackage;
// Thread-safe callback that is called on the same thread that LoadPackageAsync is issued from.
static CORE_API TTSMulticastDelegate<void(FStringView)>& GetOnAsyncLoadPackage();
static CORE_API TMulticastDelegate<void(const FString&)> OnSyncLoadPackage;
// get a hotfix delegate
static CORE_API TDelegate<void(void*, int32)>& GetHotfixDelegate(EHotfixDelegates::Type HotFix);
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Private/Serialization/AsyncPackageLoader.cpp:94
Scope (from outer to inner):
file
function static void LoadPackageAsyncCommand
Source code excerpt:
{
UE_LOG(LogStreaming, Display, TEXT("LoadPackageAsyncCommand: %s - Requested"), *PackageName);
LoadPackageAsync(PackageName, FLoadPackageAsyncDelegate::CreateLambda(
[](const FName& PackageName, UPackage* Package, EAsyncLoadingResult::Type Result)
{
UE_LOG(LogStreaming, Display, TEXT("LoadPackageAsyncCommand: %s - %s"),
*PackageName.ToString(), (Package != nullptr) ? TEXT("Loaded") : TEXT("Failed"));
}
));
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Private/Serialization/AsyncPackageLoader.cpp:589
Scope (from outer to inner):
file
function int32 LoadPackageAsync
Source code excerpt:
}
int32 LoadPackageAsync(const FPackagePath& InPackagePath, FLoadPackageAsyncOptionalParams InOptionalParams)
{
LLM_SCOPE(ELLMTag::AsyncLoading);
UE_CLOG(!GAsyncLoadingAllowed && !IsInAsyncLoadingThread(), LogStreaming, Fatal, TEXT("Requesting async load of \"%s\" when async loading is not allowed (after shutdown). Please fix higher level code."), *InPackagePath.GetDebugName());
#if DO_TRACK_ASYNC_LOAD_REQUESTS
FTrackAsyncLoadRequests::Get().TrackRequest(InPackagePath.GetDebugName(), nullptr, InOptionalParams.PackagePriority);
#endif
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Private/Serialization/AsyncPackageLoader.cpp:599
Scope (from outer to inner):
file
function int32 LoadPackageAsync
Source code excerpt:
}
int32 LoadPackageAsync(const FPackagePath& InPackagePath,
FName InPackageNameToCreate /* = NAME_None*/,
FLoadPackageAsyncDelegate InCompletionDelegate /*= FLoadPackageAsyncDelegate()*/,
EPackageFlags InPackageFlags /*= PKG_None*/,
int32 InPIEInstanceID /*= INDEX_NONE*/,
int32 InPackagePriority /*= 0*/,
const FLinkerInstancingContext* InstancingContext /*=nullptr*/,
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Private/Serialization/AsyncPackageLoader.cpp:616
Scope (from outer to inner):
file
function int32 LoadPackageAsync
Source code excerpt:
}
int32 LoadPackageAsync(const FString& InName, const FGuid* InGuid /* nullptr*/)
{
LLM_SCOPE(ELLMTag::AsyncLoading);
FPackagePath PackagePath = GetLoadPackageAsyncPackagePath(InName);
return LoadPackageAsync(PackagePath, NAME_None /* InPackageNameToCreate */, FLoadPackageAsyncDelegate(), PKG_None, INDEX_NONE, 0, nullptr);
}
int32 LoadPackageAsync(const FString& InName, FLoadPackageAsyncDelegate CompletionDelegate, int32 InPackagePriority /*= 0*/, EPackageFlags InPackageFlags /*= PKG_None*/, int32 InPIEInstanceID /*= INDEX_NONE*/)
{
LLM_SCOPE(ELLMTag::AsyncLoading);
FPackagePath PackagePath = GetLoadPackageAsyncPackagePath(InName);
return LoadPackageAsync(PackagePath, NAME_None /* InPackageNameToCreate */, CompletionDelegate, InPackageFlags, InPIEInstanceID, InPackagePriority, nullptr);
}
int32 LoadPackageAsync(const FString& InName, FLoadPackageAsyncOptionalParams InOptionalParams)
{
LLM_SCOPE(ELLMTag::AsyncLoading);
FPackagePath PackagePath = GetLoadPackageAsyncPackagePath(InName);
return LoadPackageAsync(PackagePath, MoveTemp(InOptionalParams));
}
int32 LoadPackageAsync(const FString& InName, const FGuid* InGuid /*= nullptr*/, const TCHAR* InPackageToLoadFrom, FLoadPackageAsyncDelegate InCompletionDelegate /*= FLoadPackageAsyncDelegate()*/, EPackageFlags InPackageFlags /*= PKG_None*/, int32 InPIEInstanceID /*= INDEX_NONE*/, int32 InPackagePriority /*= 0*/, const FLinkerInstancingContext* InstancingContext /*=nullptr*/)
{
LLM_SCOPE(ELLMTag::AsyncLoading);
FPackagePath PackagePath = GetLoadPackageAsyncPackagePath(InPackageToLoadFrom ? FStringView(InPackageToLoadFrom) : FStringView(InName));
FName InPackageNameToCreate;
if (InPackageToLoadFrom)
{
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Private/Serialization/AsyncPackageLoader.cpp:651
Scope (from outer to inner):
file
function int32 LoadPackageAsync
Source code excerpt:
}
}
return LoadPackageAsync(PackagePath, InPackageNameToCreate, MoveTemp(InCompletionDelegate), InPackageFlags, InPIEInstanceID, InPackagePriority, InstancingContext);
}
void CancelAsyncLoading()
{
LLM_SCOPE(ELLMTag::AsyncLoading);
// Cancelling async loading while loading is suspend will result in infinite stall
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Private/UObject/Linker.cpp:891
Scope (from outer to inner):
file
function void ConditionalFlushAsyncLoadingForLinkers
Source code excerpt:
for (FLinkerLoad* Linker : InLinkers)
{
int32 Request = LoadPackageAsync(Linker->GetPackagePath(), FLoadPackageAsyncOptionalParams{ .PackagePriority = MAX_int32 });
RequestIds.Add(Request);
}
FlushAsyncLoading(RequestIds);
}
}
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Private/UObject/UObjectGlobals.cpp:1670
Scope (from outer to inner):
file
function UPackage* LoadPackageInternal
Source code excerpt:
.LoadFlags = LoadFlags
};
int32 RequestID = LoadPackageAsync(PackagePath, MoveTemp(OptionalParams));
if (RequestID != INDEX_NONE)
{
UE_SCOPED_IO_ACTIVITY(*WriteToString<512>(TEXT("Sync "), PackagePath.GetDebugName()));
FlushAsyncLoading(RequestID);
}
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Private/UObject/UObjectGlobals.cpp:1891
Scope (from outer to inner):
file
function UPackage* LoadPackageInternal
Source code excerpt:
if (!Linker->AsyncRoot && LoadContext->GetBeginLoadCount() == 1 && IsInAsyncLoadingThread())
{
LoadPackageAsync(Linker->LinkerRoot->GetName());
}
}
else
{
bFullyLoadSkipped = true;
}
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Public/UObject/UObjectGlobals.h:710
Scope: file
Source code excerpt:
/**
* Optional parameters passed to the LoadPackageAsync function.
*/
struct FLoadPackageAsyncOptionalParams
{
/** If not none, this is the name of the package to load into (and create if not yet existing). If none, the name is take from PackagePath. **/
FName CustomPackageName { NAME_None };
/** Non Thread-safe delegate to be invoked from game-thread on completion. **/
TUniquePtr<FLoadPackageAsyncDelegate> CompletionDelegate;
/** Thread-safe delegate to be invoked at different state of progress for the given package. **/
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Public/UObject/UObjectGlobals.h:741
Scope: file
Source code excerpt:
* @return Unique ID associated with this load request (the same package can be associated with multiple IDs).
*/
COREUOBJECT_API int32 LoadPackageAsync(const FPackagePath& InPackagePath, FLoadPackageAsyncOptionalParams InOptionalParams);
/**
* Asynchronously load a package and all contained objects that match context flags. Non-blocking.
* Use this version to specify the PackagePath rather than having the other versions internally convert the InName to a PackagePath by searching the current package mount points.
* Use this version if you need to specify a packagename that is different from the packagename on disk; this is useful when loading multiple copies of the same package.
*
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Public/UObject/UObjectGlobals.h:758
Scope: file
Source code excerpt:
* @return Unique ID associated with this load request (the same package can be associated with multiple IDs).
*/
COREUOBJECT_API int32 LoadPackageAsync(const FPackagePath& InPackagePath, FName InPackageNameToCreate = NAME_None, FLoadPackageAsyncDelegate InCompletionDelegate = FLoadPackageAsyncDelegate(), EPackageFlags InPackageFlags = PKG_None, int32 InPIEInstanceID = INDEX_NONE, TAsyncLoadPriority InPackagePriority = 0, const FLinkerInstancingContext* InstancingContext = nullptr, uint32 LoadFlags = LOAD_None);
/**
* Asynchronously load a package and all contained objects that match context flags. Non-blocking.
* Use this version for convenience when you just need to load a package without notification and with default behavior from a packagename/filename.
*
* @param InName PackageName or LocalFilePath of package to load. Must be a mounted name/path. The package is created if it does not already exist.
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Public/UObject/UObjectGlobals.h:768
Scope: file
Source code excerpt:
* @return Unique ID associated with this load request (the same package can be associated with multiple IDs).
*/
COREUOBJECT_API int32 LoadPackageAsync(const FString& InName, const FGuid* InGuid = nullptr);
/**
* Asynchronously load a package and all contained objects that match context flags. Non-blocking.
* Use this version when you need to load a package with default behavior from a packagename/filename, and need to be notified when it is loaded.
*
* @param InName PackageName or LocalFilePath of package to load. Must be a mounted name/path. The package is created if it does not already exist.
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Public/UObject/UObjectGlobals.h:781
Scope: file
Source code excerpt:
* @return Unique ID associated with this load request (the same package can be associated with multiple IDs).
*/
COREUOBJECT_API int32 LoadPackageAsync(const FString& InName, FLoadPackageAsyncDelegate InCompletionDelegate, TAsyncLoadPriority InPackagePriority = 0, EPackageFlags InPackageFlags = PKG_None, int32 InPIEInstanceID = INDEX_NONE);
/**
* Asynchronously load a package and all contained objects that match context flags. Non-blocking.
* Use this version when you need to load a package with default behavior from a packagename/filename, and need to be notified when it is loaded.
*
* @param InName PackageName or LocalFilePath of package to load. Must be a mounted name/path. The package is created if it does not already exist.
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Public/UObject/UObjectGlobals.h:791
Scope: file
Source code excerpt:
* @return Unique ID associated with this load request (the same package can be associated with multiple IDs).
*/
COREUOBJECT_API int32 LoadPackageAsync(const FString& InName, FLoadPackageAsyncOptionalParams InOptionalParams);
/**
* Cancels all async package loading requests.
*/
COREUOBJECT_API void CancelAsyncLoading();
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Public/UObject/UObjectGlobals.h:960
Scope: file
Source code excerpt:
* Blocks till a set of pending async load requests are complete.
*
* @param RequestIds list of return values from LoadPackageAsync to wait for. An empty list means all requests
*/
COREUOBJECT_API void FlushAsyncLoading(TConstArrayView<int32> RequestIds);
/**
* Return number of active async load package requests
*/
COREUOBJECT_API int32 GetNumAsyncPackages();
/**
* Returns whether we are currently loading a package (sync or async)
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Internationalization/StringTable.cpp:176
Scope (from outer to inner):
file
class class FStringTableEngineBridge : public IStringTableEngineBridge, public FGCObject
function virtual int32 LoadStringTableAssetImpl
Source code excerpt:
// Begin an asynchronous load
// Note: The LoadPackageAsync callback may fire immediately if the request is invalid. This would remove the entry from AsyncLoadingStringTables, so it's valid for the find request below to fail in that case
const int32 AsyncLoadingId = LoadPackageAsync(StringTableAssetPackageNameStr, FLoadPackageAsyncDelegate::CreateRaw(this, &FStringTableEngineBridge::HandleStringTableAssetAsyncLoadCompleted));
if (AsyncLoadingId != INDEX_NONE)
{
// Load ongoing
FScopeLock AsyncLoadingStringTablesLock(&AsyncLoadingStringTablesCS);
if (FAsyncLoadingStringTable* AsyncLoadingState = AsyncLoadingStringTables.Find(StringTableAssetPackageName))
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/LevelStreaming.cpp:1666
Scope (from outer to inner):
file
function bool ULevelStreaming::RequestLevel
Source code excerpt:
{
// When loading an instanced package we want to avoid it being processed as an asset so we make sure to set it RF_Transient.
// If the package is not created here, it will get created by the LoadPackageAsync call.
// Gameworld packages (PIE) are already ignored so we can let LoadPackageAsync do its job.
if (!bIsGameWorld)
{
UPackage* NewPackage = CreatePackage(*DesiredPackageName.ToString());
NewPackage->SetFlags(RF_Transient);
}
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/LevelStreaming.cpp:1692
Scope (from outer to inner):
file
function bool ULevelStreaming::RequestLevel
Source code excerpt:
}
#endif
LoadPackageAsync(PackagePath, DesiredPackageName, FLoadPackageAsyncDelegate::CreateUObject(this, &ULevelStreaming::AsyncLevelLoadComplete), PackageFlags, PIEInstanceID, GetPriority(), InstancingContextPtr);
// streamingServer: server loads everything?
// Editor immediately blocks on load and we also block if background level streaming is disabled.
if (BlockPolicy == AlwaysBlock || (ShouldBeAlwaysLoaded() && BlockPolicy != NeverBlock))
{
if (IsAsyncLoading())
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Materials/MaterialOverrideNanite.cpp:34
Scope (from outer to inner):
file
function bool FMaterialOverrideNanite::FixupLegacySoftReference
Source code excerpt:
const FString LongPackageName = OverrideMaterialRef.GetLongPackageName();
UE_LOG(LogMaterial, Display, TEXT("Async loading NaniteOverrideMaterial '%s' for owner '%s'."), *LongPackageName, OptionalOwner ? *OptionalOwner->GetPathName() : TEXT("UNKNOWN"));
LoadPackageAsync(LongPackageName, FLoadPackageAsyncDelegate::CreateLambda(
[WeakOverrideMaterial = MakeWeakObjectPtr(OverrideMaterialEditor)](const FName&, UPackage*, EAsyncLoadingResult::Type)
{
if (UMaterialInterface* Material = WeakOverrideMaterial.Get())
{
// Use a MaterialUpdateContext to make sure dependent interfaces (e.g. MIDs) update as well
FMaterialUpdateContext UpdateContext;
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PackageMapClient.cpp:3327
Scope (from outer to inner):
file
function void FNetGUIDCache::StartAsyncLoadingPackage
Source code excerpt:
});
LoadPackageAsync(CacheObject.PathName.ToString(), LoadPackageCompleteDelegate);
}
void FNetGUIDCache::AsyncPackageCallback(const FName& PackageName, UPackage* Package, EAsyncLoadingResult::Type Result)
{
LLM_SCOPE_BYTAG(GuidCache);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SoundNodeWavePlayer.cpp:60
Scope (from outer to inner):
file
function void USoundNodeWavePlayer::LoadAsset
Source code excerpt:
UE_LOG(LogAudio, VeryVerbose, TEXT(" '%s:%s', Async loading..."), *GetNameSafe(GetOuter()), *GetName());
bAsyncLoading = true;
LoadPackageAsync(LongPackageName, FLoadPackageAsyncDelegate::CreateUObject(this, &USoundNodeWavePlayer::OnSoundWaveLoaded, bAddToRoot));
}
}
else if (bAddToRoot)
{
SoundWave->AddToRoot();
}
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/StreamableManager.cpp:1371
Scope (from outer to inner):
file
function FStreamable* FStreamableManager::StreamInternal
Source code excerpt:
#endif
// This may overwrite an existing request id, this is intentional - see comment above re: cancellation
Existing->RequestId = LoadPackageAsync(PackagePath,
NAME_None /* PackageNameToCreate */,
FLoadPackageAsyncDelegate::CreateSP(Handle, &FStreamableHandle::AsyncLoadCallbackWrapper, TargetName),
PKG_None /* InPackageFlags */,
INDEX_NONE /* InPIEInstanceID */,
Priority /* InPackagePriority */);
}
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Tests/Loading/AsyncLoadingTests.cpp:13
Scope: file
Source code excerpt:
/**
* This test demonstrate that LoadPackageAsync is thread-safe and can be called from multiple workers at the same time.
*/
IMPLEMENT_SIMPLE_AUTOMATION_TEST(FThreadSafeAsyncLoadingTest, TEXT(TEST_NAME_ROOT ".ThreadSafeAsyncLoadingTest"), EAutomationTestFlags::ClientContext | EAutomationTestFlags::EngineFilter)
bool FThreadSafeAsyncLoadingTest::RunTest(const FString& Parameters)
{
// We use the asset registry to get a list of asset to load.
IAssetRegistry& AssetRegistry = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(FName(TEXT("AssetRegistry"))).Get();
AssetRegistry.WaitForCompletion();
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Tests/Loading/AsyncLoadingTests.cpp:47
Scope (from outer to inner):
file
function bool FThreadSafeAsyncLoadingTest::RunTest
lambda-function
Source code excerpt:
[&PackagesToLoad, &RequestIDs](int32 Index)
{
RequestIDs[Index] = LoadPackageAsync(PackagesToLoad[Index].ToString());
}
);
FlushAsyncLoading(RequestIDs);
return true;
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Tests/Loading/AsyncLoadingTests_ConvertFromType.cpp:89
Scope (from outer to inner):
file
function bool FConvertFromType_SoftToHard::RunTest
Source code excerpt:
UPackage* LoadedPackage = nullptr;
UAsyncLoadingTests_ConvertFromType_V2* LoadedObject = nullptr;
int32 RequestID = LoadPackageAsync(PackagePath1,
FLoadPackageAsyncDelegate::CreateLambda(
[&LoadedPackage, &LoadedObject, &ObjectName](const FName& InPackageName, UPackage* InLoadedPackage, EAsyncLoadingResult::Type InResult)
{
LoadedPackage = InLoadedPackage;
LoadedObject = FindObject<UAsyncLoadingTests_ConvertFromType_V2>(LoadedPackage, ObjectName);
}
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Tests/Loading/AsyncLoadingTests_IsReadyForAsyncPostLoad.cpp:34
Scope (from outer to inner):
file
function bool FLoadingTests_IsReadyForAsyncPostLoad::RunTest
Source code excerpt:
// Trigger the async loading
int32 RequestId = LoadPackageAsync(FLoadingTestsScope::PackagePath1);
// Wait for a good amount of time to make sure we're really timing out because bIsReadyForAsyncPostLoad is false.
EAsyncPackageState::Type State = ProcessAsyncLoadingUntilComplete([&bPostLoadCalled]() { return bPostLoadCalled; }, 5.0);
TestNotEqual("Async loading should not have been able to complete due to bIsReadyForAsyncPostLoad being false", State, EAsyncPackageState::Complete);
TestFalse("No postload should have been called", bPostLoadCalled);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Tests/Loading/AsyncLoadingTests_IsReadyForAsyncPostLoad.cpp:81
Scope (from outer to inner):
file
function bool FLoadingTests_IsReadyForAsyncPostLoad_Flush::RunTest
Source code excerpt:
// Trigger the async loading
int32 RequestId = LoadPackageAsync(FLoadingTestsScope::PackagePath1);
// When a flush occurs, we have no choice but to ignore bIsReadyForAsyncPostLoad
FlushAsyncLoading(RequestId);
// Now we expect this to have completed in a timely manner
TestTrue("Postload should have been called", bPostLoadCalled);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Tests/Loading/AsyncLoadingTests_RecursiveLoads.cpp:197
Scope (from outer to inner):
file
function bool FLoadingTests_RecursiveLoads_FullFlushFrom_Serialize::RunTest
Source code excerpt:
// Create a request before starting the loading test so we get a request that is not tagged as partial.
RequestId = LoadPackageAsync(FLoadingTestsScope::PackagePath2);
LoadingTestScope.LoadObjects();
return true;
}
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Tests/Loading/AsyncLoadingTests_RecursiveLoads.cpp:233
Scope (from outer to inner):
file
function bool FLoadingTests_RecursiveLoads_FullFlushFrom_PostLoad::RunTest
Source code excerpt:
// Create a request before starting the loading test so we get a request that is not tagged as partial.
RequestId = LoadPackageAsync(FLoadingTestsScope::PackagePath2);
LoadingTestScope.LoadObjects();
return true;
}
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Tests/Loading/AsyncLoadingTests_Timeouts.cpp:28
Scope (from outer to inner):
file
function bool FLoadingTests_Timeouts_Postload::RunTest
Source code excerpt:
// Trigger the async loading
LoadPackageAsync(FLoadingTestsScope::PackagePath1);
LoadPackageAsync(FLoadingTestsScope::PackagePath2);
// Try to wait until all postload are finished but we're timing out after 1 seconds, which doesn't let enough time to process both postloads.
EAsyncPackageState::Type State = ProcessAsyncLoadingUntilComplete([&PostLoadCount]() { return PostLoadCount == 2; }, 1.0);
// The first call should have postloaded a single object and returned due to the elapse time.
TestEqual("Async loading should have timed out", State, EAsyncPackageState::TimeOut);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Tests/Loading/UnattendedAsyncLoadingTests.cpp:109
Scope (from outer to inner):
file
namespace UnattendedLoadTestImpl
class class FUnattendedLoader
function void LoadNextPackage
Source code excerpt:
{
UE_LOG(LogTemp, Display, TEXT("Loading %s (Remaining: %d)"), *PackageName.ToString(), PackagesToLoad.Num());
LoadPackageAsync(PackageName.ToString(),
{
.ProgressDelegate = MakeUnique<FLoadPackageAsyncProgressDelegate>(
FLoadPackageAsyncProgressDelegate::CreateLambda(
[this, ExecutionCheck = FExecutionCheck()](const FLoadPackageAsyncProgressParams& Params) mutable
{
// If we already triggered the next load from this callback, don't do anything else
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:16375
Scope: file
Source code excerpt:
/**
* Callback function used in UGameEngine::PrepareMapChange to pass to LoadPackageAsync.
*
* @param LevelPackage level package that finished async loading
* @param InGameEngine pointer to game engine object to associated loaded level with so it won't be GC'ed
*/
static void AsyncMapChangeLevelLoadCompletionCallback(const FName& PackageName, UPackage* LevelPackage, EAsyncLoadingResult::Type Result, FName InWorldHandle)
{
FWorldContext &Context = GEngine->GetWorldContextFromHandleChecked( InWorldHandle );
if( LevelPackage )
{
// Try to find a UWorld object in the level package.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:16469
Scope (from outer to inner):
file
function bool UEngine::PrepareMapChange
Source code excerpt:
STAT_ADD_CUSTOMMESSAGE_NAME( STAT_NamedMarker, *(FString( TEXT( "PrepareMapChange - " ) + LevelName.ToString() )) );
TRACE_BOOKMARK(TEXT("PrepareMapChange - %s"), *LevelName.ToString());
LoadPackageAsync(LevelName.ToString(),
FLoadPackageAsyncDelegate::CreateStatic(&AsyncMapChangeLevelLoadCompletionCallback, Context.ContextHandle)
);
}
return true;
}
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:18392
Scope (from outer to inner):
file
function static void TickAssetLoadTest
Source code excerpt:
FString TestFile = AssetLoadTest_Filenames[IndexToDo];
int32 CapturedNumProcessed = NumProcessed;
LoadPackageAsync(TestFile, FLoadPackageAsyncDelegate::CreateLambda(
[CapturedNumProcessed, bFirstTime](const FName& PackageName, UPackage* LoadedPackage, EAsyncLoadingResult::Type Result)
{
check(IsInGameThread());
check(Result == EAsyncLoadingResult::Succeeded);
UE_LOG(LogStreaming, Log, TEXT("UAssetLoadTest[%9d] - %s %s"), CapturedNumProcessed, bFirstTime ? TEXT("Loaded") : TEXT("Reloaded"), *PackageName.ToString());
RequestsOutstanding--;
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/World.cpp:7361
Scope (from outer to inner):
file
function bool FSeamlessTravelHandler::StartLoadingMap
Source code excerpt:
if (FPackagePath::TryFromMountedName(MapPackageToLoadFrom, PackagePath))
{
LoadPackageAsync(
PackagePath,
PackageFName,
FLoadPackageAsyncDelegate::CreateRaw(this, &FSeamlessTravelHandler::SeamlessTravelLoadCallback),
PackageFlags,
PIEInstanceID
);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/WorldPartition/WorldPartitionActorDescInstance.cpp:124
Scope (from outer to inner):
file
function bool FWorldPartitionActorDescInstance::StartAsyncLoad
Source code excerpt:
const FPackagePath PackagePath = FPackagePath::FromPackageNameChecked(ActorPackage);
AsyncLoadID = LoadPackageAsync(PackagePath, PackageName, FLoadPackageAsyncDelegate::CreateLambda([this, ActorPackage](const FName& PackageName, UPackage* Package, EAsyncLoadingResult::Type Result)
{
check(AsyncLoadID != INDEX_NONE);
AsyncLoadID = INDEX_NONE;
if ((Result != EAsyncLoadingResult::Succeeded) || !Package)
{
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/WorldPartition/WorldPartitionLevelHelper.cpp:654
Scope (from outer to inner):
file
function bool FWorldPartitionLevelHelper::LoadActors
Source code excerpt:
const EPackageFlags PackageFlags = InParams.DestLevel->GetPackage()->HasAnyPackageFlags(PKG_PlayInEditor) ? PKG_PlayInEditor : PKG_None;
const FPackagePath PackagePath = FPackagePath::FromPackageNameChecked(PackageToLoad);
::LoadPackageAsync(PackagePath, PackageName, CompletionCallback, PackageFlags, DestPackage->GetPIEInstanceID(), 0, &ContainerInstancingContext);
}
else
{
UPackage* InstancingPackage = nullptr;
if (PackageName != PackageToLoad)
{
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Iris/Core/Private/Iris/ReplicationSystem/ObjectReferenceCache.cpp:1888
Scope (from outer to inner):
file
namespace UE::Net::Private
function void FObjectReferenceCache::StartAsyncLoadingPackage
Source code excerpt:
//DelinquentAsyncLoads.MaxConcurrentAsyncLoads = FMath::Max<uint32>(DelinquentAsyncLoads.MaxConcurrentAsyncLoads, PendingAsyncLoadRequests.Num());
LoadPackageAsync(PackagePath.ToString(), FLoadPackageAsyncDelegate::CreateWeakLambda(ReplicationSystem,
[this](const FName& PackageName, UPackage* Package, EAsyncLoadingResult::Type Result)
{
AsyncPackageCallback(PackageName, Package, Result);
}
));
}
#Loc: <Workspace>/Engine/Source/Runtime/GameplayTags/Private/GameplayTagsManager.cpp:210
Scope (from outer to inner):
file
function void UGameplayTagsManager::LoadGameplayTagTables
Source code excerpt:
for (FSoftObjectPath DataTablePath : MutableDefault->GameplayTagTableList)
{
LoadPackageAsync(DataTablePath.GetLongPackageName());
}
return;
}
#endif // !WITH_EDITOR
#Loc: <Workspace>/Engine/Source/Runtime/LevelSequence/Private/LevelSequenceActor.cpp:315
Scope (from outer to inner):
file
function void ALevelSequenceActor::PostLoad
Source code excerpt:
{
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// We intentionally do not attempt to load any asset in PostLoad other than by way of LoadPackageAsync
// since under some circumstances it is possible for the sequence to only be partially loaded.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LoadPackageAsync(LevelSequence_DEPRECATED.GetLongPackageName(), FLoadPackageAsyncDelegate::CreateUObject(this, &ALevelSequenceActor::OnSequenceLoaded));
}
}
// Fix sprite component so that it's attached to the root component. In the past, the sprite component was the root component.
UBillboardComponent* SpriteComponent = FindComponentByClass<UBillboardComponent>();
if (SpriteComponent && SpriteComponent->GetAttachParent() != RootComponent)