TSharedPtr to RawPointer of subclass

I am trying to use the Custom user data in FAIMoveRequest
But I am getting this error.

struct NAVIGATIONSYSTEM_API FMoveRequestCustomData // this is unreal struct.
{
};
typedef TSharedPtr<FMoveRequestCustomData, ESPMode::ThreadSafe> FCustomMoveSharedPtr;
struct FMyMoveRequestCustomData : FMoveRequestCustomData
{
    bool DoSomething;
};
typedef TSharedPtr<FMyMoveRequestCustomData, ESPMode::ThreadSafe> FMyCustomMoveSharedPtr;

Usage:

FMoveRequestCustomData* Src = MoveRequest.GetUserData().Get();
FMyMoveRequestCustomData* MyCustomDataPtr = Cast<FMyMoveRequestCustomData>(Src); // getting build error here.

Error:
[C2665] see reference to function template instantiation 'To *Cast<FMyMoveRequestCustomData,FMoveRequestCustomData>(From *)' being compiled

Hi silentkratos,

Are you defining “USTRUCT()” above your “struct” definitions? You should also have a “GENERATED_BODY()” under the opening “{”.

Check out this document:

No, I am not.
simply using UStruct and Generated_Body will solve it?

Hopefully :slight_smile:

Cast is for UObjects/interfaces not regular structs. You can probably just use static_cast here or if you want to cast the sharedptr directly use StaticCastSharedPtr instead.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.