I’ve been making a game with wall running in UE 5.2, and while I haven’t been using custom gravity so far, I have seen that other people make/use whole new Character Controllers to make wall running happen. Today I booted up 5.3 for the first time and saw this in the default CharacterMovementController in my player character:
Needless to say I was excited, but after looking through the character movement controller options, and doing a quick look through its C++ code, I can’t find a way to activate it. My question is, is there a way to make this editable, and maybe manipulate it in Blueprint? I’m using the Third Person version of the controller if that makes a difference.
Make a custom movement component that extends character movement component and add a custom function to override gravity
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "CharacterMovementComponentEX.generated.h"
/**
*
*/
UCLASS()
class MYGAMENAME_API UCharacterMovementComponentEX : public UCharacterMovementComponent
{
GENERATED_BODY()
UFUNCTION(BlueprintCallable)
void SetGravDirection(const FVector& GravityDir);
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "CharacterMovementComponentEX.h"
void UCharacterMovementComponentEX::SetGravDirection(const FVector& GravityDir) {
Super::SetGravityDirection(GravityDir);
}
then inside of the character swap out the movement component with the new one
.h
// needs constructor (eg. class is called AMyCharacter)
AMyCharacter(const FObjectInitializer& ObjectInitializer);
cpp
/* needed include code */
#include "CharacterMovementComponentEX.h"
AMyCharacter::AMyCharacter(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer.SetDefaultSubobjectClass<UCharacterMovementComponentEX>(CharacterMovementComponentName))
{
// rest of your init code here if needed
}
With SetGravDirection you should be able to pass in a vector. Just to a cast to the CharacterMovementComponentEX class before calling the function.
This is awesome! Thanks! I do want to mention that if you have a Blueprint Character, you don’t need to go into C++ to change which controller it uses, you just need to go into your character movement component in your character, and in details, change the dropdown here to your custom character controller:
I also had a little trouble adding a C++ script to a Blueprint project, but I would recommend to anyone who has trouble after adding one to check these out: