Should I create a new MovementMode for stunning a character?

My question is two parts: Should I use a custom MovementMode called “Stunned” for example if I want to make a character unable to move (set its max speed to 0)? And if so, how do I create a custom movement mode?

Thank you!

Creating a custom MovementComponent will help you refine your implementation, I use a custom one for a 2D/3D point’n click adventure game to handle rotation a bit different, so yes using a movement component will help you. The bad thing is that you have to study carefully how the base MovementComponents is build to be able to adapt it to your needs.

C++ work (if you want to got that route)

The task to add you own MovementComponent will require creating a new C++ class that inherits from say UCharacterMovementComponent and a special class for you character that inherits from ACharater. You need a new base C++ class for you pawn to be able to override the existing MovementComponent of ACharacter. The following code is an base example on how you classes should look like:

//
// MyMovementComponent.h
//

#include "MyMovementComponent.generated.h"

UCLASS()
class MYGAME_API UMyMovementComponent : public UCharacterMovementComponent
{
	GENERATED_BODY()

	// Add your custom members and functions here
}

//
// MyMovementComponent.cpp
//

#include "MyMovementComponent.h"

// You code goes in the CPP file, our base class is just empty

Once you have a working MovementComponent we have to tell our character to use it:

//
// MyCharacter.h
//

#include "MyCharacter.generated.h"

UCLASS()
class MYGAME_API AMyCharacter : public ACharacter
{
	GENERATED_BODY()

public:
	/**
	* Default UObject constructor. We need this one to override the
	* MovementComponent
	*/
	AMyCharacter(const FObjectInitializer& ObjectInitializer);
}

//
// MyCharacter.cpp
//

#include "MyCharacter.h"
#include "MyMovementComponent.h"

/**
* Default UObject constructor.We need this one to override the
* MovementComponent
*/
AMyCharacter::AMyCharacter(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer.SetDefaultSubobjectClass<UMyMovementComponent>(ACharacter::CharacterMovementComponentName)) 
{
	// As you can see we use 'SetDefaultSubobjectClass' to override the class that will be used for our MovementComponent
}

With this steps you will be able to control the movement of your character the best way. On how you implement the stun logic and at the end any state related handling is totally up to you.

What about Blueprint?

If you would like to only block the player movement or input from BluePrint you can ‘Set Ignore Movement Input’ and ‘Set Ignore Look Input’ from your PlayerController.

Hope I could help you out!

Cheers,
Moss

Wow this is great! So I assume it’s not really possible to create a new MovementMode inside the editor or in blueprints? Your suggestion of nodes to use sounds like they would do the trick though.

This is still good to know how to implement them in C++ as I plan on transitionning to C++ in the near future.