Custom Character Movement Component - Epic Wiki
# Custom Character Movement Component
From Epic Wiki
Jump to: navigation, search
# Contents
- 1 Overview
- 2 Character Constructor (UE >4.6)
- 3 Character Constructor (UE <4.6)
- 4 Header File
- 5 C++ Source Code File
- 6 Accessing Custom Character Movement Component
- 7 Conclusion
# Overview
Dear Community,
If you look at CharacterMovementComponent.h the vast majority of the functions are virtual!
This is great news!
You can easily create custom character movement behaviors.... if you can get your characters to use your custom CharacterMovementComponent class!
Here's how you can do it!
# Character Constructor (UE >4.6)
First, replace
//this is your regular constructor code
}
with (where ACharacter::CharacterMovementComponentName is a string of type FName):
# Character Constructor (UE <4.6)
Replace
//this is your regular constructor code
}
with
// this is your regular constructor code
}
# Header File
Following is an example for the class definition.
pragma once
include "VictoryCharMoveComp.generated.h"
UCLASS() class UVictoryCharMoveComp : public UCharacterMovementComponent { GENERATED_UCLASS_BODY()
protected:
//Init virtual void InitializeComponent() override;
//Tick virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override; };
# C++ Source Code File
- include "VictoryGame.h"
////////////////////////////////////////////////////////////////////////// // UVictoryCharMoveComp
UVictoryCharMoveComp::UVictoryCharMoveComp(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP) {
}
void UVictoryCharMoveComp::InitializeComponent() { Super::InitializeComponent(); //~~~~~~~~~~~~~~~~~
//UE_LOG //comp Init! }
//Tick Comp void UVictoryCharMoveComp::TickComponent( float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction ){ Super::TickComponent(DeltaTime, TickType, ThisTickFunction); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//UE_LOG //custom comp is ticking!!!
}
# Accessing Custom Character Movement Component
UVictoryCharMoveComp* CustomCharMovementComp = Cast
if(CustomCharMovementComp) {
CustomCharMovementComp->CallFunction();
}
# Conclusion
Now you know how to create entirely custom movement systems for your UE4 Characters!
Enjoy!
Retrieved from "https://wiki.unrealengine.com/index.php?title=Custom_Character_Movement_Component&oldid=225"