How to override a UFUNCTION function?

There’s a function like this in Pawn.h:

   UFUNCTION(BlueprintCallable, Category=Pawn)
   virtual FRotator GetBaseAimRotation() const;

This is my declaration in a subclass:

virtual FRotator GetBaseAimRotation()override;

The definition:

FRotator AMarsEXCharacter::GetBaseAimRotation() {
           return Super::GetBaseAimRotation();    

}

And the error

   error C3668: 'AMarsEXCharacter::GetBaseAimRotation': method with override specifier 'override' did not override any base class methods

 warning C4263: 'FRotator AMarsEXCharacter::GetBaseAimRotation(void)': member function does not override any base class virtual member function
  warning C4264: 'FRotator APawn::GetBaseAimRotation(void) const': no override available for virtual member function from base 'APawn'; function is hidden

And if I remove the override keyword in the declaration
Only the warnings remain and it seems the one I wrote was never called in runtime;

So how do I override a UFUNCTION like GetBaseAimRotation correctly?

you forgot to add the const keyword in your child class implementation.

Change to this:

// .h
virtual FRotator GetBaseAimRotation() const override;

// .cpp
FRotator AMarsEXCharacter::GetBaseAimRotation() const 
{
    return Super::GetBaseAimRotation();   
}
1 Like

It works.
Problem solved