How can I prevent the character from jumping?


I want to prevent my character from jumping when specific conditions are met.

For that, I’m using the TickComponent:

void UTestGameMovementComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	const ATestGameCharacter* Character = Cast<ATestGameCharacter>(GetCharacterOwner());

	if (Character)
		MovementState.bCanJump = !Character->IsCrawling();
		MovementState.bCanSwim = !Character->IsCrawling();

But sadly, the character is still able to jump… What did I miss?

Hi FelixC,

You can try to implement your custom DoJump and implement within your custom jump condition

bool QAPawn::DoJump( bool bReplayingMoves )
	return CanJump() && <My jump condition> && CharacterMovement->DoJump(bReplayingMoves);

Best regards,

The approach you’re using should work in theory, however it seems you uncovered a bug with the implementation of ACharacter::CanJumpInternal_Implementation() checking CanEverJump() instead of IsJumpAllowed(). I’ll fix that now.

In the meantime you can override CanJumpInternal_Implementation() on the character, or DoJump() on the movement component (preferred since the Pawn one is now deprecated).