Custom Movement Mode Creation

Blueprint

You can add the following events in your Character blueprint:

  • Use Set Movement Mode to change the movement mode based on some trigger in your game. Here, we do it in Event BeginPlay for debug.

  • Event OnMovementModeChanged is called when the Movement Mode changes, and allows you to add setup or teardown (exit) code for movement mode transitions. Here, we just use it for debug.

  • In Event UpdateCustomMovement, apply the update method for the current custom movement.

If you have several custom movements, check the Custom Movement Mode byte index (sometimes called sub-mode) to know which custom movement is currently active (e.g. 0 for Climbing, 1 for Driving, etc.). Note that Blueprint does not support switching over a byte, so we use a Switch on Int with a byte-to-int conversion.

For each sub-mode, apply the update method that corresponds to the current Custom Movement Mode.

Thanks to Sw hornet for making [this tutorial (link)][2]. I found that you could even get Custom Movement Mode directly from the CharacterMovement Component, so I skipped the step where the author stores the Custom Mode in OnMovementModeChanged.

C++

I suggest you to follow james0x0A and Tomura’s method on [the link provided by Purecyn][3] in the comments. To sum up:

  • Override ACharacter::OnMovementModeChanged(EMovementMode PrevMovementMode, uint8 PrevCustomMode) if you need setup/teardown code. It corresponds to the event OnMovementModeChanged for Blueprints. Note that james0x0A mentions UCharacterMovementComponent::OnMovementModeChanged which can also be overriden, but ultimately calls ACharacter::OnMovementModeChanged.
  • Override UCharacterMovementComponent::PhysCustom(float DeltaTime, int32 Iterations) to update when a custom movement is active. It corresponds to the event UpdateCustomMovement for Blueprints.

In both cases, I suggest you to call the base methods with Super()::___, since the base implementation call the Blueprint events. It will allow you to extend the character behaviors via Blueprints later.

7 Likes