RealDocs

TSoftObjectPtr::UE_REQUIRES (constrained conversion constructor)

function CoreUObject Since 5.0
#include "UObject/SoftObjectPtr.h"
Access: public Specifiers: inline

Description

Constrained conversion constructor that copies a TSoftObjectPtr<U> into a TSoftObjectPtr<T> only when U* is implicitly convertible to T*. This is the safe, non-deprecated path for derived-to-base soft pointer conversions.

Caveats & Gotchas

  • If U* is not convertible to T*, this overload is excluded via SFINAE and the compiler instead selects the UE_SOFTOBJECTPTR_CONVERSION_DEPRECATED overload, emitting a deprecation warning since UE 5.5.
  • The constraint is evaluated at compile time only — no runtime type verification is performed, so the stored path may still refer to a class that does not satisfy the type relationship after deserialization.

Signature

template < class U UE_REQUIRES(std::is_convertible_v<U*, T*>) > [[nodiscard]] UE_FORCEINLINE_HINT TSoftObjectPtr(const TSoftObjectPtr<U>& Other)

Parameters

Name Type Description Default
Other const TSoftObjectPtr<U>& The source soft pointer whose type U must be implicitly convertible to T.

Example

Implicit upcast via constrained constructor C++
TSoftObjectPtr<UMyDerivedActor> Derived = SomeDerivedActor;
// Safe: UMyDerivedActor* is convertible to AActor*
TSoftObjectPtr<AActor> Base = Derived; // uses the UE_REQUIRES-constrained constructor

Version History

Introduced in: 5.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.