TSoftClassPtr::UE_REQUIRES
#include "UObject/SoftObjectPtr.h"
Access: public
Specifiers: inline
Description
Template constraint on TSoftClassPtr's converting constructor and assignment operators. Ensures that only classes related by inheritance can be implicitly converted, matching the same safety guarantees as TSubclassOf.
Caveats & Gotchas
- • This constraint applies to the copy constructor TSoftClassPtr(const TSoftClassPtr<TClassA>&) and the operator=(const TWeakObjectPtr<TClassA>&) and operator=(const TSoftObjectPtr<TClassA>&) overloads. Incompatible class types produce a hard compile error.
- • The constraint mirrors TSubclassOf's convertibility rules: a TSoftClassPtr<ACharacter> can be assigned from a TSoftClassPtr<AMyCharacter> (derived), but not from a TSoftClassPtr<AActor> (base) without an explicit cast.
- • Unlike TSharedPtr where the constraint is on raw pointer assignment, here the softly-referenced class has not necessarily been loaded. The constraint is purely a static type-safety guarantee and has no impact on asset loading.
Signature
UE_REQUIRES(std::is_convertible_v<TClassA*, TClass*>) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| TClassA | template parameter | The source class type. Must be implicitly convertible to TClass* for the constructor or assignment to be selected. | — |
Example
Implicit conversion from derived soft class pointer C++
TSoftClassPtr<ACharacter> CharacterClass;
TSoftClassPtr<AMyCharacter> MyCharClass(FSoftObjectPath("/Game/BP_MyCharacter.BP_MyCharacter_C"));
// OK: AMyCharacter* is convertible to ACharacter*
CharacterClass = TSoftClassPtr<ACharacter>(MyCharClass);
// ERROR — AActor* is NOT convertible to ACharacter* via UE_REQUIRES:
// TSoftClassPtr<ACharacter> Bad = TSoftClassPtr<AActor>(...); Tags
Version History
Introduced in: 5.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?