0

When using Unreal Engines built in Custom Movement Component, I understand that in order to set a custom Child of the FSavedMoveCharacter Class as the active FSavedMoveCharacter, the Function AllocateNewMove Is used.

AllocateNewMove() returns a "FSavedMovePtr", so my custom child of the FSavedMoveCharacter must be converted to a "FSavedMovePtr"

When I try to do this using the most common method it fails:

FSavedMovePtr UCustomMoveComponent::FNetworkPredictionData_Client_Custom::AllocateNewMove()
{
    return FSavedMovePtr(new FSavedMove_Custom());
}

Using this method, no suitable conversion is found

"cannot convert from 'UCustomMoveComponent::FSavedMove_Custom *' to 'FSavedMovePtr'"

FSavedMovePtr is defined as

typedef TSharedPtr<class FSavedMove_Character> FSavedMovePtr;

It appears that it is defined as a pointer to the FSavedMove_Character class so I cannot understand why converting a child of this class to a pointer would fail

My custom Move component is defined as

class FSavedMove_Custom : FSavedMove_Character
{
    typedef FSavedMove_Character Super;

    uint8 Saved_WantsToSprint :1;

    virtual bool CanCombineWith(const FSavedMovePtr& NewMove, ACharacter* InCharacter, float MaxDelta) const override;
    virtual void Clear() override;
    virtual uint8 GetCompressedFlags() const override;
    virtual void SetMoveFor(ACharacter* C, float InDeltaTime, FVector const& NewAccel, FNetworkPredictionData_Client_Character& ClientData) override;
    virtual void PrepMoveFor(ACharacter* C) override;

};

In short, how can the above class be converted to a TSharedPtr of itself?

4
  • 1
    Use return MakeShared<FSavedMove_Custom>();
    – kiner_shah
    Commented Jul 10 at 6:22
  • This method results in the following error: 'return': cannot convert from 'TSharedRef<UCustomMoveComponent::FSavedMove_Custom,ESPMode::ThreadSafe>' to 'TSharedPtr<FSavedMove_Character,ESPMode::ThreadSafe>' Converted to a refrence rather than a ptr? Commented Jul 10 at 6:49
  • 3
    Why do you use private inheritance?
    – pptaszni
    Commented Jul 10 at 6:57
  • 2
    changing to public inheritance (FSavedMoveCustom : FSavedMove_Character to FSavedMoveCustom : public FSavedMove_Character) fixed this issue, Thank you Commented Jul 10 at 7:06

0

Browse other questions tagged or ask your own question.