TSharedRef
#include "Templates/SharedPointer.h" Description
A non-nullable, non-intrusive reference-counted smart pointer for non-UObject types. Guarantees the reference is always valid — there is no null state.
Caveats & Gotchas
- • Has no default constructor. You must provide a valid object at construction time.
- • Convert to TSharedPtr with ToSharedPtr() if you need a nullable version to pass to APIs that accept it.
- • Same UObject restriction as TSharedPtr — do not use for UObject types.
Signature
template<class ObjectType, ESPMode InMode> class TSharedRef Example
Non-nullable subsystem reference C++
TSharedRef<FMySubsystem> Subsystem = MakeShared<FMySubsystem>();
Subsystem->Initialize();
// No null check needed — TSharedRef is always valid Functions (2)
Comparison 1 ▼
| Access | Type | Name |
|---|---|---|
| public | function | TSharedRef::UEOpEquals |
Construction 1 ▼
| Access | Type | Name |
|---|---|---|
| public | function | TSharedRef::UE_REQUIRES |
Properties
| Access | Type | Name |
|---|---|---|
| private | property | TSharedRef::Object |
| private | property | TSharedRef::SharedReferenceCount |
See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?