Converting Between Shared Pointers and Shared References
Converting between Shared Pointers and Shared References is a common practice. Shared References implicitly convert to Shared Pointers, and provide the additional guarantee that the new Shared Pointer will reference a valid object. Conversion is handled by the normal syntax:
TSharedPtr<FMyObjectType> MySharedPointer = MySharedReference;
You can create a Shared Reference from a Shared Pointer with the
Shared Pointer function,
ToSharedRef, as long as the Shared Pointer references a non-null object. Attempting to create a Shared Reference from a null Shared Pointer will cause the program to assert.
// Ensure your shared pointer is valid before dereferencing to avoid a potential assertion.
MySharedReference = MySharedPointer.ToSharedRef();