I’ve had a hell of a time trying to figure out a good way to do this. I need a function to run once when the player lands after falling. I basically have been doing it in the tick function like so:
if (!GetCharacterMovement()->IsMovingOnGround()) {
if (GetCharacterMovement()->IsMovingOnGround()) {
Landing();
}
}
But this just decided to stop working for some reason and I figure it’s prob a ■■■■ poor way to do it anyway. I’ve gone down a hell of a Google rabbit hole on this and come up with nothing. Came across OnMovementModeChanged() but can’t get it implemented to save my life. Apparently it doesn’t work in UE5 anymore or something? Any direction would be greatly appreciated.
// 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 LANDSIGN_API UCharacterMovementComponentEX : public UCharacterMovementComponent
{
GENERATED_BODY()
virtual void ProcessLanded(const FHitResult& Hit, float remainingTime, int32 Iterations) override;
};
CPP
// Fill out your copyright notice in the Description page of Project Settings.
#include "CharacterMovementComponentEX.h"
void UCharacterMovementComponentEX::ProcessLanded(const FHitResult& Hit, float remainingTime, int32 Iterations) {
Super::ProcessLanded(Hit, remainingTime, Iterations);
GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Orange, "Landed");
}
Changes to character in c++ (i called it LandSignCharacter)
Header
// Its CDO
ALandSignCharacter(const FObjectInitializer& ObjectInitializer);
in cpp
find CDO implementation and extend it swapping movement for the new class
Honestly, getting Landed to work made me realize that that’s what I was missing when I tried using OnMovementModeChanged earlier. I didn’t think about declaring the override.
You answered a question I was literally just looking up too. I keep seeing the Super and wondering what it’s about. Recently shifted from Unity and C# to Unreal and C++ so having to crash course everything. Thank you very much.
Oh yeah, ran into this face first almost immediately but I have experience in other languages too so was basically like riding a bike and going back to basics.