RealDocs

TSharedRef

struct Core Since 4.0
#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.

Signature

template<class ObjectType, ESPMode InMode> class TSharedRef

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.

Example

Non-nullable subsystem reference C++
TSharedRef<FMySubsystem> Subsystem = MakeShared<FMySubsystem>();
Subsystem->Initialize();
// No null check needed — TSharedRef is always valid

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.