RealDocs

TSoftClassPtr::LoadAsync

function CoreUObject Since 4.17
#include "UObject/SoftObjectPtr.h"
Access: public Specifiers: const

Description

Kicks off an asynchronous load of the class asset and returns a request ID. The completion delegate fires on the game thread; the caller is responsible for casting the resolved object to the correct type inside the callback.

Caveats & Gotchas

  • The completion delegate receives an FSoftObjectPath, not a UClass* — you must call ResolveObject() and cast yourself, because this wrapper does not perform the type-checked Get() that the synchronous variant does.
  • The returned int32 request ID can be used to cancel the load; letting it go out of scope without cancelling is safe but may result in the delegate firing after the initiating object is destroyed — always capture a weak reference in the delegate.

Signature

int32 LoadAsync(FLoadSoftObjectPathAsyncDelegate InCompletionDelegate, FLoadAssetAsyncOptionalParams InOptionalParams = FLoadAssetAsyncOptionalParams()) const

Parameters

Name Type Description Default
InCompletionDelegate FLoadSoftObjectPathAsyncDelegate Delegate invoked on the game thread when the async load completes or fails. The delegate receives the resolved soft path; validate the type yourself inside the callback.
InOptionalParams FLoadAssetAsyncOptionalParams Optional load parameters such as priority. FLoadAssetAsyncOptionalParams()

Return Type

int32

Example

Async load with a game-thread callback C++
UPROPERTY(EditAnywhere)
TSoftClassPtr<AMyEnemy> EnemyClass;

void AMySpawner::BeginAsyncLoad()
{
    EnemyClass.LoadAsync(
        FLoadSoftObjectPathAsyncDelegate::CreateWeakLambda(this,
            [this](const FSoftObjectPath& LoadedPath)
            {
                UClass* Class = Cast<UClass>(LoadedPath.ResolveObject());
                if (Class)
                {
                    GetWorld()->SpawnActor<AMyEnemy>(Class, GetActorTransform());
                }
            })
    );
}

Version History

Introduced in: 4.17

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.