RealDocs

TSoftClassPtr::LoadSynchronous

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

Description

Synchronously loads the class referenced by this soft pointer if it is not already in memory, then returns it. Returns null if the pointer is null or if the loaded object is not a valid child of the template type.

Caveats & Gotchas

  • Calling this on the game thread will stall rendering and input for the duration of the load — use the async variant with a streaming manager for anything that might not already be in memory.
  • The internal IsChildOf check means you can get null back even when the path resolves successfully if the loaded class does not inherit from TClass; always validate the return value.
  • Unlike TSoftObjectPtr<T>::LoadSynchronous, this variant performs a dynamic_cast internally, so it is slightly more expensive than a raw FSoftObjectPtr load.

Signature

UClass* LoadSynchronous() const

Return Type

UClass*

Example

Spawning from a soft class pointer C++
UPROPERTY(EditAnywhere)
TSoftClassPtr<AMyEnemy> EnemyClass;

void AMySpawner::SpawnEnemy()
{
    if (UClass* Class = EnemyClass.LoadSynchronous())
    {
        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.