A Custom Character Movement Component
Used Unreal Engine Version: 4.22
Since the Unreal Engine Wiki is somewhat outdated in specific areas and I am not allowed to edit there, because they are working on a new one, I spare you the hassle to figure it out for yourself and present to you: the custom character movement component :D
If you want a character that supports more movement types, you have to extend character movement component. Here is how to do it:
First, create a new class inheriting from UCharacterMovementComponent
:
// MainCharacterMovementComponent.h
UCLASS()
class MYGAME_API UMainCharacterMovementComponent :
public UCharacterMovementComponent
{
GENERATED_BODY()
public:
UMainCharacterMovementComponent(const FObjectInitializer& ObjectInitializer);
protected:
virtual void InitializeComponent() override;
virtual void TickComponent
(
float DeltaTime,
enum ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction
) override;
};
and implement it:
// MainCharacterMovementComponent.cpp
#include "MainCharacterMovementComponent.h"
UMainCharacterMovementComponent::UMainCharacterMovementComponent(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
// You stuff here
}
void UMainCharacterMovementComponent::InitializeComponent()
{
Super::InitializeComponent();
}
//Tick Comp
void UMainCharacterMovementComponent::TickComponent
(
float DeltaTime,
enum ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction
){
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}
Then, extend ACharacter
and replace it’s default UCharacterMovementComponent
:
// ThirdPersonCharacter.h
UCLASS()
class MYGAME_API AThirdPersonCharacter : public ACharacter
{
GENERATED_BODY()
public:
// .............................................................. Constructor
// Sets default values for this character's properties
AThirdPersonCharacter(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
}
Then implement it like this to replace the component:
// ThirdPersonCharacter.cpp
AThirdPersonCharacter::AThirdPersonCharacter(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer.SetDefaultSubobjectClass
<UMainCharacterMovementComponent>(ACharacter::CharacterMovementComponentName))
{
// Your implementation stuff here
}
Hope, this helps :)
Written with StackEdit.
Unreal Engine C++ Tutorial Series
Want more? Have a look into the following tutorials!
Comments
Post a Comment