Skip to main content

[Unreal Engine][C++] How to create a custom CharacterMovementComponent

[Unreal Engine][C++] How to create a custom CharacterMovementComponent

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

Popular posts from this blog

Newer Super Mario Bros. Wii unter Linux mit Patchimage

Super Mario Bros. ist ein Klassiker. Dazu muss sicher nicht viel gesagt werden. Doch auch die neuesten Ableger der Serie wie New Super Mario Bros. Wii erfreuen sich großer Beliebtheit. Eine Weile lang machte ein Spiel namens Newer Super Mario Bros. Wii großes Aufsehen. Die Forsetzung zum Original von Nintendo wurde inoffiziell vom Newer-Team in 3-jähriger Entwicklerarbeit erstellt, hat 128 neue Level und überzeugt durch die außerordentliche Qualität des Hacks. An dieser Stelle sei gesagt, dass ihr das Spiel nur legal spielen könnt, wenn ihr New Super Mario Bros. Wii selbst besitzt. Falls dies nicht der Fall ist, kauft es bitte zuerst. Illegal heruntergeladene Spiele werden nicht unterstützt und von mir ausdrücklich nicht befürwortet . (Eine Windows-Anleitung findet ihr hier: WiiDatabase .de) Also, los gehts: Dumpt euer originales New Super Mario Bros. Wii z.B. mit USB Loader GX (auf + klicken) kopiert den Ordner New Super Mario Bros. Wii [SMNP01] auf euren PC Nun ...

Ubuntu 16.04 USB-Stick - "Das Ziel ist schreibgeschützt" lösen

Es gibt Dinge, die dürfen in einem nutzerfreundlichen Betriebssystem einfach nicht passieren. Vor allem dürfen Sie aber nicht monatelang bestehen bleiben. Mit Ubuntu 16.04 kann ich Freunden und Bekannten Ubuntu einfach nicht mehr empfehlen, wenn selbst ich an einfachsten Aufgaben scheitere. Gemeint ist hier das Kopieren von Dateien auf USB-Sticks. Trotz jahrelanger Ubuntu/Linux-Erfahrung gelang es mir erst nach gründlicher Recherche das Problem zu beheben. Ein Laie hat hier keine Chance. Damit ihr nicht lange suchen müsst, hier das Problem samt Lösung: Problem Datei oder Ordner auf Fat32-USB-Stick kopieren oder anlegen schlägt fehl mit der Meldung "Das Ziel ist schreibgeschützt". Lösung das Paket fuse-posixovl installieren und Ubuntu neu starten sudo apt-get install fuse-posixovl Viel Erfolg

[Unreal Engine][C++] How to create a simple trigger actor

[Unreal Engine][C++] How to create a simple trigger actor A Simple Trigger Volume in C++ Used Unreal Engine Version: 4.22 This is the first post of a small series of Unreal Engine C++ Tutorials. Keep in mind, that Unreal’s API changes rapidly and often. I still hope, this may be of some use to others. Coming from Unity, programming in C++ for Unreal is rather painful. I hope to give you some assistance and make life a little bit easier. Whay, would you say, should we make our own trigger actor? There is ATriggerVolume , right? Yes, there is, but inheriting from it is difficult and rather undocumented. I tried and failed. Yes, we have to give up some of ATriggerVolume 's functionality, but we learn a lot and at least we know exactly what it’s doing. First, we’ll create a new C++ class, inheriting from Actor , called SimpleTriggerVolume . Let’s add a protected property to hold a reference to our trigger component: /** Shape of the trigger volume componen...