RealDocs

FSoftObjectPath::TryLoad

function CoreUObject Since 4.18
#include "UObject/SoftObjectPath.h"
Access: public Specifiers: const

Description

Synchronously loads the referenced asset via LoadObject and returns the result. Returns nullptr if the path is null or if the asset fails to load.

Caveats & Gotchas

  • This is a synchronous, potentially blocking call. On large assets it can stall the game thread for hundreds of milliseconds. Use LoadAsync for assets that do not need to be ready immediately.
  • Must only be called from the game thread. Calling from a render thread, audio thread, or task graph worker is not safe and may trigger asserts or deadlocks.

Signature

COREUOBJECT_API UObject* TryLoad(FUObjectSerializeContext* InLoadContext = nullptr) const;

Parameters

Name Type Description Default
InLoadContext FUObjectSerializeContext* Optional serialization context used when called from within a nested load callstack. nullptr

Return Type

UObject*

Example

Synchronous load during BeginPlay C++
UPROPERTY(EditAnywhere)
FSoftObjectPath WeaponMeshPath;

void AMyCharacter::BeginPlay()
{
    Super::BeginPlay();
    if (UStaticMesh* Mesh = Cast<UStaticMesh>(WeaponMeshPath.TryLoad()))
    {
        WeaponMeshComponent->SetStaticMesh(Mesh);
    }
}

Version History

Introduced in: 4.18

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.