Custom CharacterMovementComponent client-side issue

Hi,

I have a strange problem with creating a custom movement type. I’m pretty new to C++ so hopefully this is something simple I’ve overlooked.

I’ve set up a child class of CharacterMovementComponent where I override PhysCustom to implement my own custom movements types. Should be simple right? Well…

In my override of PhysCustom below I’m just printing text to screen. On server this text is spammed every tick until the movement mode is changed, as expected. Yet on client it writes it only Ticks once and reverts to another movement mode.

Is this a replication problem? If anyone can offer any insight into why this is happening I would be very grateful.

If there’s any more information I can add please let me know.

Thanks,

TestCharacterMove.cpp derived from UCharacterMovementComponent.

#include "ReplicationTest.h"
#include "TestCharacterMove.h"

UTestCharacterMove::UTestCharacterMove(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
}

void UTestCharacterMove::SetPhysSwinging()
{
	NewCustomMovementMode = TESTMOVE_Swinging;
	SetMovementMode(MOVE_Custom, NewCustomMovementMode);
}

void UTestCharacterMove::SetPhysFalling()
{
	SetMovementMode(MOVE_Walking);
}

void UTestCharacterMove::PhysCustom(float deltaTime, int32 Iterations)
{
	Super::PhysCustom(deltaTime, Iterations);
    //Print string every tick
	GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::White, "CustomMoveMode");
}

Header file:

#pragma once

#include "GameFramework/CharacterMovementComponent.h"
#include "TestCharacterMove.generated.h"

/** Movement modes for Characters.  */
UENUM(BlueprintType)
enum ECustomMovementMode
{
	TESTMOVE_Swinging		UMETA(DisplayName = "Swinging"),
};

UCLASS()
class REPLICATIONTEST_API UTestCharacterMove : public UCharacterMovementComponent
{
	GENERATED_UCLASS_BODY()

public:
	UPROPERTY(Category = MovementMode, BlueprintReadOnly)
		TEnumAsByte<enum ECustomMovementMode> NewCustomMovementMode;

protected:
	virtual void PhysCustom(float deltaTime, int32 Iterations) override;

public:
    //Set movement type on right click
	void SetPhysSwinging();
    //Set movement type on left click
	void SetPhysFalling();
};

Ok so I got this working.

My problem was nothing to do with my custom movement component. I simply had to ensure that my input was processed on the server as well as the client. This explains why I was getting a single tick of my requested movement before it reverted back to a different one. The client was running the code but was getting reverted to a different movement state by the server that was ignorant of my input.

Slowly wrapping my head around UE4. Feels good to figure these things out.