Announcement

Collapse
No announcement yet.

Why is K2_OnMovementModeChanged not visible for override?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • replied
    After a little fiddling around, here is a solution:

    .h file:
    Code:
    virtual void OnMovementModeChanged(EMovementMode PrevMovementMode, uint8 PrevCustomMode) override;
    .cpp file:
    Code:
    // Prints previous and current EMovementMode values to LogTemp on movement mode change
    void AMyCharacter::OnMovementModeChanged(EMovementMode PrevMovementMode, uint8 PrevCustomMode)
    {
        Super::OnMovementModeChanged(PrevMovementMode, PrevCustomMode);
        const UEnum* EnumPtr = FindObject<UEnum>(ANY_PACKAGE, TEXT("EMovementMode"), true);
        UE_LOG(LogTemp, Log, TEXT("Previous movement mode is %s"), *EnumPtr->GetNameStringByValue((int64)PrevMovementMode));
    
        const UEnum* EnumPtrZwa = FindObject<UEnum>(ANY_PACKAGE, TEXT("EMovementMode"), true);
        UE_LOG(LogTemp, Log, TEXT("Current movement mode is %s"), *EnumPtrZwa->GetNameStringByValue((int64)GetCharacterMovement()->MovementMode.GetValue()));   
    }
    In other words, you have to get the current movement mode by:

    Code:
    GetCharacterMovement()->MovementMode.GetValue()

    Leave a comment:


  • replied
    I see.

    In this case, is there any way to access NewMovementMode and NewCustomMode (kind of the point of this whole excersize) within cpp?

    Leave a comment:


  • replied
    What happens is:
    1 - OnMovementModeChanged is called from C++.
    2 - WIthin OnMovementModeChanged, K2_OnMovementModeChanged is called, so you can use it in Blueprint.



    OnMovementModeChanged is NOT "visible" to Blueprint :
    Code:
    virtual void OnMovementModeChanged(EMovementMode PrevMovementMode, uint8 PreviousCustomMode = 0);


    K2_OnMovementModeChanged IS "visible" as BlueprintImplementableEvent:
    Code:
    UFUNCTION(BlueprintImplementableEvent, ...)
    void K2_OnMovementModeChanged(EMovementMode PrevMovementMode, EMovementMode NewMovementMode, uint8 PrevCustomMode, uint8 NewCustomMode);


    OnMovementModeChanged code:
    Code:
    void ACharacter::OnMovementModeChanged(EMovementMode PrevMovementMode, uint8 PrevCustomMode)
    {
        ...
    
        K2_OnMovementModeChanged(PrevMovementMode, CharacterMovement->MovementMode, PrevCustomMode, CharacterMovement->CustomMovementMode);
        ...
    }

    Error message:
    Code:
    error C3668: 'AMyCharacter::K2_OnMovementModeChanged': method with override specifier 'override' did not override any base class methods
    In a member function declaration or definition, override ensures that the function is virtual and is overriding a virtual function from a base class.
    https://en.cppreference.com/w/cpp/language/override

    Leave a comment:


  • replied
    I'm confused by this fact because this:

    Click image for larger version

Name:	OnMovementModeChanged.png
Views:	62
Size:	23.5 KB
ID:	1687678

    looks like the K2_OnMovementModeChanged definition, even though the non-K2 one (plain OnMovementModeChanged) is the virtual function. On top of that, isn't the error message usually "trying to override non-virtual function" not "function doesn't exist"? Is there some trick going on behind the scenes here?

    Leave a comment:


  • replied
    Instead of K2_OnMovementModeChanged you could use OnMovementModeChanged.
    You can see in docs that K2_OnMovementModeChanged is not virtual but OnMovementModeChanged is, so you can override it:

    https://docs.unrealengine.com/en-US/...ter/index.html

    I need a confirmation about this but K2_* is exposed C++ functions for Blueprints.

    Leave a comment:


  • replied

    K2_OnMovementModeChanged isn't a virtual function in the ACharacter class, and you can't override a non-virtual function.

    Leave a comment:


  • Why is K2_OnMovementModeChanged not visible for override?

    I want to override the K2_OnMovementModeChanged method from ACharacter. Maybe this is a syntax thing, but...

    .h file:
    Code:
    // Class declaration:
    class CHARACTERMOVEMENT_API AMyCharacter : public ACharacter
    {
        virtual void K2_OnMovementModeChanged(EMovementMode PrevMovementMode, EMovementMode NewMovementMode, uint8 PrevCustomMode, uint8 NewCustomMode) override;
    }
    .cpp file:
    Code:
    void AMyCharacter::K2_OnMovementModeChanged(EMovementMode PrevMovementMode, EMovementMode NewMovementMode, uint8 PrevCustomMode, uint8 NewCustomMode)
    {
        Super::K2_OnMovementModeChanged(PrevMovementMode, NewMovementMode, PrevCustomMode, NewCustomMode);
        UE_LOG(LogTemp, Log, TEXT("Movement Mode Changed"));
    }
    This returns a compilation error:

    Code:
    error C3668: 'AMyCharacter::K2_OnMovementModeChanged': method with override specifier 'override' did not override any base class methods
    But this function does exist:
    https://docs.unrealengine.com/en-US/...ged/index.html

    And you can also override this function in blueprints. So why can't I override the function?
Working...
X